flex布局

发布时间 2023-06-29 12:08:20作者: Webwhl
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
        }
        .item {
            width: calc(calc(100% / 3) - 10px);
            border: 1px solid blue;
            height: 30px;
            line-height: 30px;
            color: red;
            margin-bottom: 10px;
        } 
        .item:nth-child(n+4) {
            margin-bottom: 0;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
        <div class="item">5</div>
        <div class="item">6</div>
    </div>
</body>
</html>