美文网首页
css 瀑布流布局

css 瀑布流布局

作者: 暴躁程序员 | 来源:发表于2023-10-12 16:54 被阅读0次

    一、实现瀑布流

    1. 通过外层容器的 width 固定宽、 column-count 列数、column-gap 列间距属性实现瀑布流
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>瀑布流</title>
        <style>
          * {
            margin: 0;
            padding: 0;
          }
          html,
          body {
            height: 100%;
          }
          .container {
            width: 300px;
            column-count: 3; 
            column-gap: 20px;
          }
          .item {
            break-inside: avoid;
            width: 100px;
            margin-bottom: 10px;
            background-color: yellowgreen;
          }
          .item > img {
            width: 100px;
          }
        </style>
      </head>
      <body>
        <div class="container">
          <div class="item">
            <img src="./images/1.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
          <div class="item">
            <img src="./images/2.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
          <div class="item">
            <img src="./images/3.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
          <div class="item">
            <img src="./images/4.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
          <div class="item">
            <img src="./images/4.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
          <div class="item">
            <img src="./images/2.png" alt="" />
            <h1>标题</h1>
            <div>情详情详情详情详情详情</div>
          </div>
        </div>
      </body>
      <script></script>
    </html>
    

    相关文章

      网友评论

          本文标题:css 瀑布流布局

          本文链接:https://www.haomeiwen.com/subject/uglobdtx.html