学无先后,达者为师

网站首页 编程语言 正文

使用grid布局解决flex布局最后一行不足的问题

作者:qcc0716 更新时间: 2022-01-08 编程语言
<!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>Document</title>
    <style>
        .box1 {
            display: grid;
            justify-content: space-between;
            grid-template-columns: repeat(auto-fill, 100px);
            grid-gap: 10px;
            width: 400px;
            border: 1px solid red;
        }
        .box2 {
            width: 100px;
            height: 100px;
            background-color: skyblue;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div class="box1">
        <div class="box2"></div>
        <div class="box2"></div>
        <div class="box2"></div>
        <div class="box2"></div>
        <div class="box2"></div>
        <div class="box2"></div>
        <div class="box2"></div>
    </div>
</body>
</html>

原文链接:https://blog.csdn.net/qcc0716/article/details/119667880

栏目分类
最近更新