clear mdn文檔 clear只是清除浮動,不能緩解【高度塌陷】
https://developer.mozilla.org/zh-CN/docs/Web/CSS/clear
值
none
元素不會被向下移動以清除浮動。left
元素被向下移動以清除左浮動。right
元素被向下移動以清除右浮動。both
元素被向下移動以清除左右浮動。inline-start
元素被向下移動以清除其包含塊的起始側浮動,即 ltr 時清除左浮動,rtl 時清除右浮動。inline-end
元素被向下移動以清除其包含塊的結束側浮動,即 ltr 時清除右浮動,rtl 時清除左浮動。
解決塌陷
https://codesandbox.io/s/funny-water-4oh3p7?file=/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>高度塌陷</title>
<style>
.box {
margin: 100px;
width: 100px;
height: 100px;
background: red;
float: left;
}
.container {
background: #000;
display: flex;
}
</style>
</head>
<body>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</body>
</html>