文档流例程小册【处理高度塌陷】

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 时清除左浮动。

none
left
right
both

解决塌陷

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>

float: none;
float: none;

inline-block;
inline-block;

table-cell
table-cell

display: flex
flex

position: absolute;
position: absolute;

position: fixed;
position: fixed;

display: table-caption
display: table-caption

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。