首页 > 技术文章 > css after 伪元素清除浮动样式

ericblog1992 2020-05-15 09:26 原文

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

<style type="text/css">
/* 声明清除浮动的样式 */
.clearfix:after {
content: "";
display: block;
height: 0;
visibility: hidden;
clear: both;
}
/* ie6 7 专门清除浮动的样式*/
.clearfix {
*zoom:1;
}


.one {
width: 500px;
border: 1px solid red;
}

.damao {
float: left;
width: 200px;
height: 200px;
background-color: purple;
}
.ermao {
float: left;
width: 250px;
height: 250px;
background-color: skyblue;
}

.two {
width: 700px;
height: 150px;
background-color: #000;
}
</style>
</head>
<body>

<div class="one clearfix">
<div class="damao"></div>
<div class="ermao"></div>
</div>

<div class="two"></div>

</body>
</html>

推荐阅读