css 一行展示4个元素,不足的左对齐

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            .container{
                display: flex;
                flex-wrap: wrap;
            }
            .list{
                width: 24%;
                height: 100px;
                background-color: aqua;
                margin-top: 10px;
            }
            .list:not(:nth-child(4n)){
                margin-right: calc(4%/3);
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
            <div class="list"></div>
        </div>
        <script type="text/javascript">
            
        </script>
    </body>
</html>

 

posted @ 2022-06-14 16:38  Name张三  阅读(717)  评论(0编辑  收藏  举报