清除浮动问题请进

我看教程里清除浮动标准写法是

.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0} 
.clearfloat{zoom:1}

但是为什么我这个只是写

#box:after{content:"";clear:both;display:block;}

这么写也能清除浮动,那么visibility和height属性为什么也要写?

附上代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<style>
#box{}
.son{width:100px;height:100px;float:left;}
#green{background:green;}
#red{background:red;}
#blue{background:blue;}
#black{background:black;}
#box:after{content:"";clear:both;display:block;}
#box{*zoom:1}
</style>
</head>
<body>
<div id="box">
    <div id="green" class="son"></div>
    <div id="red" class="son"></div>
    <div id="blue" class="son"></div>
</div>
</body>
</html>


stone310
浏览 1997回答 3
3回答

第二热情

.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0} 这段代码  就是clear:both 是用于清除浮动的,其他部分都是为了隐藏这个块的内容不影响整个布局结构的现在 用的比较多的应该是 .clearfloat:after{display:table;clear:both} 如果没记错的话

OlderSkee

没什么区别,写上高 宽为0,更保险而已。。
打开App,查看更多内容
随时随地看视频慕课网APP