看完必会的grid布局

<!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>
        div[class=grid-container] {
            /* 水平垂直居中方式 */
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);

            /* 如果行轨道和列轨道小于盒子容器,还可以对轨道进行对齐 */
            /* 列轨道对齐 */
            /* align-content: center; */
            /* align-content: end; */

            /* 水平轨道 */
            /* justify-content: center; */
            /* justify-content: end; */
            /* justify-content: space-between; */
            width: 800px;
            height: 500px;
            display: grid;
            grid-gap: 10px;
            /* 垂直方向 */
            /* align-items: end; */
            /* align-items: center; */

            /* 水平方向 */
            /* justify-items: center; */
            /* justify-items: space-between; */
            background-color: #ccc;
            grid-template-columns: 1fr 1fr 1fr;
            /* grid-template-columns: 100px 100px 100px; */
        }

        .grid-container>div {
            padding: 20px;
            background-color: aquamarine;
        }
    </style>
</head>

<body>
    <div>
        <div class="grid-container">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
            <div>6</div>
        </div>
    </div>
</body>

</html>

/* 垂直方向 */

            /* align-items: end; */

            align-items: center;

 /* 水平方向 */

            /* justify-items: center; */

            /* justify-items: space-between; */

 /* 如果行轨道和列轨道小于容器,还可以对轨道进行对齐 */

            /* 列轨道对齐 */

            align-content: center;

            /* align-content: end; */

            /* 水平轨道 */

            /* justify-content: center; */

            /* justify-content: end; */

            /* justify-content: space-between; */

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值