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

2023-01-10  本文已影响0人  凌川江雪

clear mdn文档 clear只是清除浮动,不能缓解【高度塌陷】

https://developer.mozilla.org/zh-CN/docs/Web/CSS/clear

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

上一篇 下一篇

猜你喜欢

热点阅读