代码示例
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<style type="text/css">
header, main, footer{
width: 1000px;
margin: 0 auto;
}
/*设置头部*/
header{
background: silver;
height: 150px;
}
/*设置主体*/
main{
background: #bfa;
height: 600px;
margin: 10px auto;
}
/*设置底部*/
footer{
background: orange;
height: 150px;
}
nav, article, aside{
height: 100%;
float: left;
}
/*设置左侧导航*/
nav{
width: 200px;
background: yellow;
}
/*设置中间文章*/
article{
width: 580px;
background: pink;
margin: 0 10px;
}
/*设置右侧内容*/
aside{
width: 200px;
background: gainsboro;
}
</style>
<body>
<!--网页头部-->
<header></header>
<!--网页主体-->
<main>
<!--左侧导航-->
<nav></nav>
<!--中间文章-->
<article></article>
<!--右侧内容-->
<aside></aside>
</main>
<!--网页底部-->
<footer></footer>
</body>
</html>
个人理解
- 布局中,元素位置只和他的兄弟元素有关,main中的子元素即使超出了main,与不会影响main兄弟元素的布局位置
- 每个盒子都自成一界,有自己的文档流,内部如何布局与外部元素无关