我正在使用Bootstrap 4,并创建了一个项目列表,并将其分为两两列(参见图片)。当我将网站缩小到移动尺寸屏幕时,它显示如下:
但是我想当我将其缩小到移动设备大小(响应)时,它只显示在一列中。我希望它像这样:
这是我的代码:
.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">Lorem ipsum dolor sit amet.</h2>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum, dolor sit amet consectetur adipisicing.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
</ul>
</div>
即使这是一个完全的初学者问题,也要感谢您的帮助。
答案 0 :(得分:1)
您可以只添加几个media
查询,以便CSS仅适用于特定大小的设备。
为了使其在移动设备上成为一列,在较大的设备上成为两列,您需要在media
查询中说“在特定设备宽度上”,将创建的CSS变成两列,应用这个。
.list-group {
display: grid;
grid-template-columns: 1fr;
}
@media screen and (min-width:767px) {
.list-group {
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">Lorem ipsum dolor sit amet.</h2>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet consectetur.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum, dolor sit amet consectetur adipisicing.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum dolor.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem, ipsum.
<i class="fas fa-check"></i>
</li>
<li class="list-group-item list-group-item-action">
Lorem ipsum dolor sit amet.
<i class="fas fa-check"></i>
</li>
</ul>
</div>
(运行代码段查看移动设备布局,然后全屏查看较大的设备布局)