I write a html page containing a header on top, following by a section part and an aside part, and then a footer part, and write some CSS codes for styling. here is the html and CSS code:
body{
width: 80%;
margin: 0 auto;
background-color: peachpuff;
}
header, section, aside, footer, article{
margin: 10px;
padding: 10px;
text-align: center;
background-color: aliceblue;
border: 1px solid cadetblue;
font-size: 2rem;
width: 100%;
box-sizing: border-box;
}
header>h1{
height: 100px;
font-size: 2.5rem;
text-shadow: 2px 2px 2px red;
}
article {
width: 85%;
margin: 0 auto;
}
section{
width: 60%;
height: 300px;
margin-right:3px;
display: inline-block;
/*float:left;*/
}
aside{
width: 37%;
margin-left:3px;
height: 300px;
float: right;
display: inline-block;
}
footer{
display: block;
width: 100%;
background-color: aliceblue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<header>
<h1>This is header.</h1>
</header>
<section>
this is section.
<article>this is article.</article>
</section>
<aside>aside part.</aside>
<footer>this is footer.</footer>
</body>
</html>
I set width:100% for header and footer, and it should make then to stretch so fill all the body width, as body is their parent node. but I notice that it cause header and footer that go beyond the body width at right side! if I comment that, every thing will be fine, but why it doesn't work as expected?
and second question, I want section and aside to be located next to each other, and by setting float:right; for aside tag they are, but if I set float:left; for section element too, while they still are next to each other, footer become their background too! why that happens?
thanks.
marginmake's the header push himself out of the bodyautobecause they are block level elements. No need to set width to100%.