zl程序教程

您现在的位置是:首页 >  其他

当前栏目

文档流code案例小汇【处理高度塌陷】

2023-02-25 18:16:08 时间

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