<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<!-- 高度塌陷分为两类 -->
<!-- 前提:只有盒子BFC+高度auto时,浮动--计算高度时会自动包裹下边缘,而绝对定位会忽略高度 -->
<!-- 1.子盒子浮动导致父盒子撑不开了,高度塌陷,用BFC(overflow: auto;)可以解决 -->
<!-- 2.子绝父相 子重叠,父盒子撑不开了,高度塌陷,不能用BFC解决 -->
<!--浮动的例子,子绝父相不解释 -->
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
<style>
.container {
background-color: blue;
overflow: auto;
/* 现在直接一般不用浮动直接display:flex解决 */
}
.item {
width: 100px;
height: 100px;
background-color: aqua;
float: left;
border: 1px solid red;
}
</style>
</html>