?
Solved

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

Posted on 2014-03-01
5
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

800 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