Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

CSS grid-gap Property - ช่องว่างระหว่าง Grid Rows และ Columns

ใช้ grid-gap (Shorthand ของ grid-row-gap และ grid-column-gap) กำหนดช่องว่างระหว่าง Grid Rows และ Columns

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        .container {
            display: grid;
            background-color: green;
            grid-template-columns: auto auto;
            padding: 20px;
            grid-gap: 20px 20px; /* row-gap column-gap */
        }
        .ele {
            background-color: orange;
            border: 2px solid gray;
            padding: 35px;
            font-size: 30px;
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>Game Board</h1>
    <div class="container">
        <div class="ele">1</div>
        <div class="ele">2</div>
        <div class="ele">3</div>
        <div class="ele">4</div>
        <div class="ele">5</div>
        <div class="ele">6</div>
    </div>
</body>
</html>

รูปแบบ: grid-gap: <row-gap> <column-gap>; หากให้ค่าเดียว grid-gap: 20px; จะใช้ทั้ง Row และ Column

หมายเหตุ: ปัจจุบันใช้ gap แทน (รองรับ Flexbox ด้วย)