網格grid的分享和總結(參考web前端微信公衆號內容)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>網格佈局Grid用法</title>
    <style>
        body{
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
        }
        .gridtable{
            display: grid;
            /* width: 100%;(容器的寬度能夠規定也能夠不固定,其中若不規定寬度則追溯到父集的寬度直至body ,高也同樣*/
            /* grid-template-columns: 30% 40% 30%; */
            /*能夠大於100%,也能夠用實際的數值*/
            /* grid-template-rows: 50px 60px ; */
            /*能夠大於100%,也能夠用實際的數值*/
            width: 400px;
            height: 400px;
        }
        .gridtable>div{
            text-align: center;
        }
        .gridtable>div:nth-child(1){
            background: deepskyblue;
            grid-column-start: 1;
            grid-column-end: 3;
        }
        .gridtable>div:nth-child(2){
            background: deeppink;
        }
        .gridtable>div:nth-child(3){
            background: darkcyan;
            grid-row-start: 2;
            grid-row-end: 4;
        }
        .gridtable>div:nth-child(4){
            background: lightsalmon;
            grid-column-start: 2;
            grid-column-end: 4;
        }
        .gridtable>div:nth-child(5){
            background: lightcoral;
        }
        .gridtable>div:nth-child(6){
            background: darkseagreen;
        }
    </style>
</head>
<body>
    <div class="gridtable">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
    </div>
</body>
</html>

clipboard.png
第一張代碼生成的頁面圖,第二張是我的對grid-column-start(end)中的column
的備註,其中黑線表明column,下方綠色數字表明個數,這樣就很容易理解這行代碼的意思了,同理可知row!
clipboard.pnghtml

相關文章
相關標籤/搜索