我将尝试制作一个网格布局,其中有2个垂直的和2个水平的部分重复出现。然后是2个水平的,2个垂直的,我们再次重复。
就像这样:
.container {
max-width:940px;
margin: 0 auto;
}
.grid-container {
counter-reset: div;
display:grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 186px;
grid-gap:20px;
justify-content:center;
grid-template-areas:
"vert1 vert2 hor1 hor1"
"vert1 vert2 hor2 hor2"
"hor3 hor3 vert3 vert4"
"hor4 hor4 vert3 vert4"
}
.item-a {
grid-area: vert1;
}
.item-b {
grid-area: vert2;
}
.item-c {
grid-area: hor1;
}
.item-d {
grid-area: hor2;
}
.item-e {
grid-area: hor3;
}
.item-f {
grid-area: hor4;
}
.item-g {
grid-area: vert3;
}
.item-h {
grid-area: vert4;
}
.item-j {
grid-area: hor2;
}
.item-k {
grid-area: hor2;
}
.item-l {
grid-area: hor2;
}
.item-m {
grid-area: hor2;
}
.grid-container > div {
box-shadow: 0 0 11px 0 #b9b9b9;
}
.grid-container > div:before {
counter-increment: div;
content: counter(div);
margin: auto;
font-size: 40px;
display:flex;
}
<div class="container">
<div class="grid-container">
<div class="item-a"></div>
<div class="item-b"></div>
<div class="item-c"></div>
<div class="item-d"></div>
<div class="item-e"></div>
<div class="item-f"></div>
<div class="item-g"></div>
<div class="item-h"></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
我找不到一种方式来使它出现在自动(无限)行中,只能通过grid-template-areas实现。
grid-template-areas:
"vert1 vert2 hor1 hor1"
"vert1 vert2 hor2 hor2"
"hor3 hor3 vert3 vert4"
"hor4 hor4 vert3 vert4"
有人有任何想法吗?
(关于 IT 技术)