Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with CSS Centering.

Featured Replies

I really didn't want to post a link to the site I'm building until it's more complete but I'm stuck on a problem.

 

I'm using HTML5/CSS3 and I'm having problems getting the Menu and the Image centered (I haven't looked into the menu much, been mainly focused on the Image.

 

Here is the Div class:

 #hero-image {
 	display: block;
 	width: 80%;
 	max-width: 100%
}

The container surrounding the div mentioned above is:

.container {
	width: 940px;
	padding: 0 10px;
	margin: 0 auto;
}

 

If I lower the percentage of the image width then it seems to go centered but I can't seem to figure out why I can't have the image bigger and centered. I thought It must be the padding after temporarily removing this it made no difference.

 

Here is the site:

http://edgar.ldn.kualo.net/~lmpmeuk/web/busybees/

 

HTML section:

		<header>
			<div class="container clearfix dashes-bottom">
				<a href="/" title="Click here to go home" id="logo">
				<img src="img/logo-main.png" alt="logo">
				</a>
			</div>
			<div class="container clearfix">
				<nav>
					<ul>
						<li><a href="/about">About</a></li>
						<li><a href="/products-and-prices">Products and Prices</a></li>
						<li><a href="/gallery">Gallery</a></li>
						<li><a href="/contact">Contact me</a></li>
					</ul>
				</nav>
			</div> <!--end container-->
			
			<div class="container clearfix">
			
					<div id="hero-image">
									<a href="/">
				<img src="img/slider/kitchen_adventurer_cheesecake_brownie.jpg" alt="hero">
				</a>
					</div>
			
			</div> <!--end hero container-->
		</header>

I hope someone can help,

 

Thanks.

Edited by ~Luke

The hero image link -

Remove those 3 styles and just give it a display of inline block.

 

The container that this link resides in should have text-align center.

 

As a side note anything that is a block element or has display block does not require a width or max width of 100% as width 100% is the browser default.

  • Author

Thanks for the advice.

 

I removed the 3 lines and did a display: inline;

 

However it didn't center. I centered by doing a text-align: center; in the hero-image attribute - is this correct formatting?

 

 

I tried doing the same for the nav but that didn't work so I tried on the ul and li entered within nav - no joy.

 

Any idea's?

  • Author

Any ideas anyone? I don't know how to progress with this.

 

Many thanks.

Remove float:left; on nav ul.

 

Remove float: left; on nav ul li and add display: inline;

  • Author

Thank Rbrt, Jane and Jack.

 

I have sorted it now with the advice give.

 

So for centering the header image I used text-align:center; in the container it was contained it.

 

Just so I can get an understanding, why wouldn't it be the standard centering attribute of margin:0 auto;

 

Thanks again.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.