Solved

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

Posted on 2014-03-01
5
379 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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…

840 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