Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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).

809 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