[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

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

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
centem
Asked:
centem
  • 2
  • 2
1 Solution
 
GaryCommented:
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
 
centemAuthor Commented:
Thank you. Why doesn't my margin-right and margin-left center the page?
0
 
GaryCommented:
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
 
centemAuthor Commented:
Thanks for your quick response and your example code. It helped me fix it.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now