常见页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.top {
height: 50px;
background-color: gray;
}
.banner {
width: 980px;
height: 150px;
background-color: gray;
margin: 10px auto;
}
.box {
width: 980px;
height: 300px;
margin: 0 auto;
background-color: white;
}
li {
list-style: none;
}
.box li {
float: left;
width: 237px;
height: 300px;
margin-right: 10px;
background-color: gray;
}
.box .last {
margin-right: 0;
}
.footer {
height: 200px;
background-color: gray;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="top"></div>
<div class="banner"></div>
<div class="box">
<ul>
<li></li>
<li></li>
<li></li>
<li class="last"></li>
</ul>
</div>
<div class="footer"></div>
</body>
</html>
浮动布局注意点
1. 浮动和标准流的父盒子搭配 : 先用标准流的父元素排列上下位置, 之后内部子元素采取浮动排列左右位置
2. 浮动的盒子只会影响浮动盒子后面的标准流, 不会影响前面的标准流
如果第一个盒子不浮动, 第二个盒子浮动, 会发生什么情况
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.d1 {
height: 200px;
width: 200px;
background-color: pink;
}
.d2 {
float: left;
height: 200px;
width: 200px;
background-color: navajowhite;
}
</style>
</head>
<body>
<div class="d1"></div>
<div class="d2"></div>
</body>
</html>
因为第一个盒子没有浮动. 是标准流 , 独占一行, 所以第二个盒子会在第二行显示