gpt4 book ai didi

css - 向右浮动列表组

转载 作者:太空宇宙 更新时间:2023-11-04 06:29:16 27 4
gpt4 key购买 nike

我是 Bootstrap 新手,有 15 个列表项。我希望最后 7 个元素在右边(见当前情况图片)。我已经尝试了几个教程,但它不起作用。你们能帮帮我,给我一些方法吗?

即使这是一个完全初学者的问题,我也很感激你的帮助。

我想这样做:

like this

list-item

<section class="info2">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Der einfache uns sichere Weg</h2>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
</ul>
</div>
</section>

最佳答案

CSS-Grid 可以做到这一点。

我们只提供 2 个“列”并将行数设置为“8”(在本例中为 15 -7 = 8)

.list-group {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(8, 1fr);
grid-auto-flow:column;
}
<section class="info2">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Der einfache uns sichere Weg</h2>
</div>
</div>
<ul class="list-group list-group-flush">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
<li>Item 15</li>
</ul>
</div>
</section>

或者

如果 li 的数量未知 并且最后 7 项需要在第二列中,这也可以使用 :nth-last- child (-n+7)

.list-group {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-flow: column;
}

li {
grid-column: 1;
}

li:nth-last-child(-n+7) {
grid-column: 2;
}
<section class="info2">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Der einfache uns sichere Weg</h2>
</div>
</div>
<ul class="list-group list-group-flush">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
<li>Item 15</li>
<li>Item 16</li>
<li>Item 17</li>
<li>Item 18</li>
<li>Item 19</li>
<li>Item 20</li>
</ul>
</div>
</section>

关于css - 向右浮动列表组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54823888/

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