Reputation: 93
I don't have much HTML/CSS experience, but I am trying to get a simple layout going where I have a centered div acting as the page container. I have tried looking up other examples, but I can't figure out why mine doesn't work (the header appears but is left justified, I want it centered):
html:
<!DOCTYPE html>
<html>
<head>
<title>title</title>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<div id="header"></div>
</div>
</body>
</html>
css:
body {
background: #fff;
font-family: Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
text-align: center;
}
#container {
background: #bbb;
width: 800px;
margin: 0, auto;
}
#header, #footer {
background: #333;
height: 40px;
}
Upvotes: 0
Views: 736
Reputation: 2273
body {
background: #fff;
font-family: Helvetica, Arial, sans-serif;
width: 100%; /* You need to mention the width here (Good way)*/
padding: 0;
text-align: center;
}
#container {
background: #bbb;
width: 800px;
margin: 0 auto; /* You are doing wrong here (margin: 0, auto;) */
}
#header, #footer {
background: #333;
height: 40px;
}
margin: 0 auto;
(valid) instead of margin: 0, auto;
(invalid)
Upvotes: 0
Reputation: 1981
You have a , between margin:0
and auto;
this is an invalid CSS term
margin: 0, auto;
needs to be
margin: 0 auto;
Upvotes: 0