Solved

Unable to center page, header tag and section tag not working

Posted on 2014-03-01
5
375 Views
Last Modified: 2014-03-01
Hi,
I a few things that are not working as I (newbie) expect from what I have coded.  I'm trying to get my h1 and h2 tags to sit to the right of the img in my header tag but it shows below the image. Also, I have a section tag with css setting a border for it but the border won't show. I'm also trying to center the page but that isn't working either. The html and css is below. Thank you very much.

******** HTML **************************

<!DOCTYPE HTML>
	<head>
		<title>Building Contractor</title>
		<link rel="stylesheet" type="text/css" href="styles.css" />
	</head>
	
	<body>
			<header>
				<img src="imgs/InnInKeyWestFlorida_bnr.png" />
						<h1>Hello World</h1>
						<h2>Hello World</h2>
			</header>
			<nav>
				<ul>
					<li><a href="#">Home</a></li>
					<li><a href="#">Projects</a></li>
					<li><a href="#">Services</a></li>
					<li><a href="#">Contact Us</a></li>
				</ul>
			</nav>
			<section>
				Here is the section element
			</section>
			<footer>
				<h3>This is the footer</h3>
			</footer>
	</body>
	
</HTML>

***************CSS**************************

html {
	margin: 0 auto;
}
body {
	margin-left: auto;
	margin-right: auto;
	margin-top: 0;
}

nav ul {
	list-style: none;
}
nav li {
	display: inline;
}
nav a {
	font-weight: bold;
	text-decoration: none;
	padding: 1em 2em;
	border-right: 2px solid gold;
}
section {
	margin: auto auto;
	height: 400px;
	width: 200px
	border: 5px solid black;
}
footer {
	margin-bottom: 0;
}

Open in new window

0
Comment
Question by:centem
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39897483
For the border you are missing a semi colon after the width
section {
      margin: auto auto;
      height: 400px;
      width: 200px;
      border: 5px solid black;
}

Open in new window


Wrap your H1 and H2 in this
<div class="head-container">
</div>


and add this css
.head-container {
    display:inline-block
}
0
 

Author Comment

by:centem
ID: 39897524
Thank you. Why doesn't my margin-right and margin-left center the page?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39897528
To use margin:0 auto you need to have everything between your body tags wrapped in a container and then give that container a set width e.g.

<div id="container">
...everything else here
</div>


CSS
#container {
width:900px;
margin:0 auto;
}
0
 

Author Closing Comment

by:centem
ID: 39897668
Thanks for your quick response and your example code. It helped me fix it.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now