代码:
<!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>
</head>
<style>
.left{
float: left;
width: 100px;
height: 100px;
background: red;
}
.right{
margin-left: 100px;
background: blue;
}
.fr{
float: left;
height: 30px;
}
.clear:after{
content: "";
display: block;
clear: both;
height: 0;
}
</style>
<body>
<div class="left"></div>
<div class="right">
<div class="clear">
<div class="fr">111</div>
</div>
</div>
</body>
</html>
结果:
为什么 right
的高度会变成 100px
,而不是 30px
,求大佬解惑。
这个例子我之前写过解析,你可以看看应该,会有帮助的点击查看