我是Bootstrap的新手,有15个列表项。我希望最后7项在右边(请参阅当前情况的图片)。我已经尝试了几个教程,但是没有用。你们可以帮我一下,给我一些方法吗?
即使您是一个初学者,也非常感谢您的帮助。
我想这样做:
<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>
答案 0 :(得分:1)
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>
答案 1 :(得分:0)
.list-group {
display:grid !important;
grid-template-columns:repeat(2,1fr);
}
li:nth-child(1) {
grid-column:1/3 !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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>
答案 2 :(得分:0)
不知道这是您想要的吗,看看吗?
.list-group{
display: block !important;
min-width: calc((1000px / 7) * 7);
overflow:auto;
}
li:nth-last-child(-n+7) {
display: block;
overflow: hidden;
float: left;
width: calc(100% / 7);
white-space: nowrap;
text-overflow: ellipsis;
font-size: 10px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<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>