清除浮动解决父元素高度塌陷问题

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#wrap{
width: 500px;
/*height: 300px;*/
background: red;
}
#contain{
width: 300px;
height: 300px;
background: blue;
float: right;
}
#wrap:after{
content:".";
height:0;
visibility:hidden;
display:block;
clear:both;
}
</style>
</head>
<body>
<div id="wrap" >
<div id="contain">

</div>
</div>
</body>
</html>

posted on 2019-12-03 15:35  刘二鹏  阅读(138)  评论(0编辑  收藏  举报