I don't quite understand why this code acts like this. If I do this...
HTML:
<body>
<header>
<h1>
MY HEADER
</h1>
</header>
<article>
<p>Lorem ipsum dolor sit amet...</p>
</article>
<footer>
<p>This is my footer</p>
</footer>
</body>
CSS:
body {
width: 60%;
margin: 0 auto;
}
article {
background: #AAA;
}
footer {
background: #888;
}
header {
color: #333;
background: #0F0;
}
I end up with this:
But if I add a border to the elements.
CSS:
body {
width: 60%;
margin: 20px auto;
}
article {
border: 1px solid red;
background: #AAA;
}
footer {
border: 1px solid red;
background: #888;
}
header {
border: 1px solid red;
color: #333;
background: #0F0;
}
I end up with this:
Why is this?
How do I get the second result without adding borders?
EDIT I finally went with a simple normalization.
- { margin: 0; }
I first wanted to get away from that, since the page I'm building is for showing a group of beginners how to make a simple html/css page. And I think it's hard enough for non-coders to grasp without getting into these weird behaviors.