3. clear: both 无法清除当前元素右侧的浮动对象clear 无论在何种情况下(clear:left,clear:right,clear:both)都只能让作用了clear属性的标签的前面的标签起到效果。
非常疑惑,那岂不是只能清除掉左侧的浮动对象咯,clear:both和clear:right有什么用咯?
我们还是拿刚才的案例,不过不同的是,我们让所有的div右浮动
现在!!!!!!!!!!
我们让第二个盒子的右侧不允许有浮动的元素出现,我们就要用到clear:right或者clear:both了
[mw_shl_code=applescript,true]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.box {
width: 400px;
height: 300px;
border: 1px solid #000;
}
.box div {
width: 100px;
height: 100px;
float: right;
font-size: 50px;
line-height: 100px;
text-align: center;
color: aliceblue;
border: 1px solid #000;
}
.box1 {
background-color: #66ccff;
}
.box2 {
background-color: #0a0;
clear: both;
/*或者 clear:right*/
}
.box3 {
background-color: #f00;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
</div>
</body>
</html>
[/mw_shl_code]
4. 总结