CSS - 网格区域



描述

grid-area 属性将网格项目分配到网格容器内的命名网格区域,您希望将该项目放置在该区域中。

示例

这是一个示例 -

您可以使用编辑和运行选项编辑并尝试运行此代码。

<!DOCTYPE html>
<html>
<head>
    <title>CSS - grid-area</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style type="text/css">
        .grid-container {
            display: grid;
            grid-template: auto auto;
            color: white;
            text-align: center;
            width: 360px;
            border: 2px solid rgb(29, 231, 80);
            background-color: rgb(29, 231, 80);
        }
        .grid-container > div {
            background-color: rgb(228, 9, 9);
            border: 2px solid rgb(29, 231, 80);
            padding: 10px;
        }
        .grid-item2 {
            border: 2px solid rgb(29, 231, 80);
            padding: 10px;
            grid-area: 2 / 2 / span 2 / span 2;
        }   
    </style>
</head>
<body>
    <h3>Grid item 2 start on row 2 and column 2, and span 2 rows and 2 columns.</h3>
    <div class="grid-container">
        <div class="grid-item1">Grid item 1</div>
        <div class="grid-item2">Grid item 2</div>
        <div class="grid-item3">Grid item 3</div>
        <div class="grid-item4">Grid item 4</div>
        <div class="grid-item5">Grid item 5</div>
        <div class="grid-item6">Grid item 6</div>
        <div class="grid-item7">Grid item 7</div>
        <div class="grid-item8">Grid item 8</div>
        <div class="grid-item9">Grid item 9</div>
    </div>
</body>
</html>      
广告