##clear mdn文档 clear只是清除浮动,不能缓解【高度塌陷】 developer.mozilla.org/zh-CN/docs/…
值
-
none 元素不会被向下移动以清除浮动。
-
left 元素被向下移动以清除左浮动。
-
right 元素被向下移动以清除右浮动。
-
both 元素被向下移动以清除左右浮动。
-
inline-start 元素被向下移动以清除其包含块的起始侧浮动,即 ltr 时清除左浮动,rtl 时清除右浮动。
-
inline-end 元素被向下移动以清除其包含块的结束侧浮动,即 ltr 时清除右浮动,rtl 时清除左浮动。
##解决塌陷 codesandbox.io/s/funny-wat…
<!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>
####float: none;
####inline-block;
####table-cell
####display: flex
####position: absolute;
####position: fixed;
####display: table-caption