1 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
要實(shí)現(xiàn)此目的,您需要為所有三種長度(42.5%、48.75% 和 52.5%)找到一個(gè)公共分隔線。使用通用分隔線,您可以創(chuàng)建適當(dāng)數(shù)量的列來容納每個(gè)網(wǎng)格區(qū)域。
在下面的示例中,我創(chuàng)建了 400 列,每列寬度為 0.25% (400 * .25 = 100%)。
然后它跨越正確數(shù)量的列跨越網(wǎng)格區(qū)域:
45.00 / .25 = 180
48.75 / .25 = 195
52.50 / .25 = 210
它可能不完全是您正在尋找的,但希望這個(gè)概念可以幫助您前進(jìn)。
沒有對 HTML 進(jìn)行任何更改。
.atul {
display: grid;
grid-template-columns: repeat(400, .25%);
grid-auto-rows: 50px; /* for demo only */
grid-row-gap: 30px; /* note that you need to create column gaps through
the proper distribution of columns, because if you
use `grid-column-gap`, it will add a gap between
all 400 columns */
}
.card:nth-child(1) {
grid-column: 1 / 180;
grid-row: 1 / 3;
}
.card:nth-child(2) {
grid-column: -1 / -210; /* starting at the end line of the grid
(works only in explicit grids) */
grid-row: 1 / 2;
}
.card:nth-child(3) {
grid-column: -1 / -210;
grid-row: 2 / 3;
}
/* starting at the 4th item, target even items only */
.card:nth-child(n + 4):nth-child(even) {
grid-column: 1 / 195;
}
.card:nth-child(n + 4):nth-child(odd) {
grid-column: -1 / -195;
}
.card:nth-child(4),
.card:nth-child(5) {
grid-row: 3;
}
.card:nth-child(6),
.card:nth-child(7) {
grid-row: 4;
}
.card:nth-child(8),
.card:nth-child(9) {
grid-row: 5;
}
.card:nth-child(10),
.card:nth-child(11) {
grid-row: 6;
}
.card:nth-child(12),
.card:nth-child(13) {
grid-row: 7;
}
<div class="atul">
<div class="card" style="background-color: red;">Card 1</div>
<div class="card" style="background-color: green;">Card 2</div>
<div class="card" style="background-color: yellow;">Card 3</div>
<div class="card" style="background-color: skyblue;">Card 4</div>
<div class="card" style="background-color: skyblue;">Card 5</div>
<div class="card" style="background-color: skyblue;">Card 6</div>
<div class="card" style="background-color: skyblue;">Card 7</div>
<div class="card" style="background-color: skyblue;">Card 8</div>
<div class="card" style="background-color: skyblue;">Card 9</div>
<div class="card" style="background-color: skyblue;">Card 10</div>
<div class="card" style="background-color: skyblue;">Card 11</div>
<div class="card" style="background-color: skyblue;">Card 12</div>
<div class="card" style="background-color: skyblue;">Card 13</div>
</div>
jsFiddle 演示
- 1 回答
- 0 關(guān)注
- 186 瀏覽
添加回答
舉報(bào)