标签:red 添加 ext 样式 text 方案 htm har back
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>自元素浮动导致父元素塌陷解决方案</title>
<style type="text/css">
/*
1在父级元素中添加overflow:hidden;
2.在父元素中定义类伪类classclearbox1:after
{
content: "";
display: block;
clear: both;
}
3.在父元素样式中加入 display: inline-block;
4.在得知子元素高度时给复原设置高度
*/
.box1{
height: 100px;
border: 10px solid red;
/*display: inline-block;*/
/*overflow: hidden;*/
}
/* .clearbox1:after{
content: "";
display: block;
clear: both;
}*/
.box2{
width: 100px;
height: 100px;
background-color: gray;
float: left;
}
</style>
</head>
<body>
<div class="box1 clearbox1">
<!-- <div class="box3"></div>-->
<div class="box2"></div>
</div>
</body>
</html>
标签:red 添加 ext 样式 text 方案 htm har back
原文地址:https://www.cnblogs.com/xiaokemo/p/12495886.html