
批改狀態(tài):不合格
老師批語:想一下什么原因?
網(wǎng)格布局是一個基于二維網(wǎng)格布局的系統(tǒng),以下是關(guān)于網(wǎng)格布局我個人的理解
網(wǎng)格容器
display: grid;
網(wǎng)格項目
<div class="container">
<div class="item"></div>
</div>
網(wǎng)格單元
網(wǎng)格區(qū)域
<div class="container">
<div class="yellow"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
.container {
display: grid;
grid-template-columns: repeat(3, 10em);
grid-template-rows: repeat(3, 10em);
place-content: center;
.item {
width: 5em;
height: 5em;
background-color: red;
}
.yellow {
width: 5em;
height: 5em;
background-color: yellow;
}
}
.container {
display: grid;
grid-template-columns: repeat(3, 10em);
grid-template-rows: repeat(3, 10em);
grid-template-areas: "a a a" "b b b" "c c c"; //改變位置
place-content: center;
.item {
width: 5em;
height: 5em;
background-color: red;
}
.yellow {
width: 5em;
height: 5em;
background-color: yellow;
grid-area: b; //改變位置
}
}
網(wǎng)格軌道
軌道間隙
我們通過容器屬性 gap 指定行間隙 和 列間隙,效果如下
gap: 0.5em 1em;
<div class="container">
<div class="yellow"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
.container {
display: grid;
// 顯示網(wǎng)格單元
grid-template-columns: repeat(3, 10em);
grid-template-rows: repeat(3, 10em);
grid-template-areas: "a a a" "b b b" "c c c"; //網(wǎng)格區(qū)域
place-content: center;
gap: 0.5em 1em;
// 隱式網(wǎng)格單元
grid-auto-flow: row; //默認(rèn)排列方式左右 設(shè)置隱士單元高度
grid-auto-rows: 10em;
.item {
width: 5em;
height: 5em;
background-color: red;
}
.yellow {
width: 5em;
height: 5em;
background-color: yellow;
grid-area: b; //區(qū)域
}
}
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號