gpt4 book ai didi

css 网格自定义布局流程

转载 作者:行者123 更新时间:2023-11-28 17:02:34 24 4
gpt4 key购买 nike

我需要列出要格式化的内容,我有一些东西

<div class="container">
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
</div>

像这样。元素数量是动态的,我总是希望前 6 个元素处于行模式,所有其他元素都在列中。例如

- - - - - -
- -
- -
- -
- -

元素顺序应该是:

1 2 3 4 5 6
7 8
9 10
11 12

自由填充选项,使用网格或 flex 环绕

最佳答案

使用grid会是这样

.container {
display: grid;
/* Create six columns and four rows */
grid-template-columns: repeat(6, 1fr);
grid-template-rows: repeat(4, 50px);
}

/* Select every second, starting at sixth */
.item:nth-child(2n+7) {
/* Specify the column to put the item */
grid-column: 3;
}
<div class="container">
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
<span class="item">Item</span>
</div>

关于css 网格自定义布局流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51993213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com