Flex布局实例:流式布局

版权声明:哼!坏人!这是我辛辛苦苦码的! https://blog.csdn.net/DurianPudding/article/details/87936216
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>流式布局</title>
  <style>
    .main {
      width: 200px;
      height: 150px;
      background-color: black;
      display: flex;
      flex-flow: row wrap;
      align-content: flex-start;
    }

    .item {
      /*
      假如需要并排放置两个带边框的框,可通过将 box-sizing 设置为 "border-box"。
      这可令浏览器呈现出带有指定宽度和高度的框,并把边框和内边距放入框中。
       */
      box-sizing: border-box;
      background-color: white;
      height: 50px;
      border: 1px solid red;

      /*
      宽度占比25%,不伸缩
       */
      flex: 0 0 25%;
    }
  </style>
</head>
<body>
<h2>流式布局</h2>
<p>每行的项目数固定,会自动分行</p>
<div class="main">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/DurianPudding/article/details/87936216