高度塌陷:
当一个元素被设置为浮动,那么它的高度将会不被文档流识别,从而让在文档流中的div给覆盖。
BFC:
DIV有Float浮动的属性,又不至于因为高度塌陷而被覆盖。
设置BFC:
子元素设置margin影响到父元素:
附代码:
<%--
Created by IntelliJ IDEA.
User: user
Date: 2021/8/21
Time: 8:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<style>
.box1{
width:200px;
height:200px;
background-color: yellow;
/*float: left;*/
}
.box2{
width:200px;
height:200px;
background-color: gold;
overflow: hidden;
}
.box3{
width: 100px;
height:100px;
background-color: green;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="box1">
<div class="box3">
</div>
</div>
<%--<div class="box2"></div>--%>
</body>
</html>