简体   繁体   English

图像网格:桌面上为 5 x 5,移动设备上为 3 x 9

[英]Grid of images: 5 by 5 on desktop but 3 by 9 on mobile devices

I need to make a grid of images of 5 by 5, on 3/4 of the screen on a desktop, but 3 by 9 (last row has only 1 image) when is a mobile device.我需要在桌面屏幕的 3/4 上制作 5 x 5 的图像网格,但在移动设备时则是 3 x 9(最后一行只有 1 张图像)。

All images will be 120x175 always.所有图像始终为 120x175。

Desired desktop:想要的桌面:

在此处输入图片说明

Desired mobile:想要的手机:

在此处输入图片说明

I currently have a grid of 4 by 4, because Bootstrap works with col divisible by 3 or 4.我目前有一个 4 x 4 的网格,因为 Bootstrap 使用可被 3 或 4 整除的 col。

But the problem is the grid doesn't accomodate on mobile devices.但问题是网格不适用于移动设备。

Current desktop:当前桌面:

在此处输入图片说明

Current mobile:当前手机:

在此处输入图片说明

Code:代码:

 <div class="row"> <div class="col-md-1"></div> <div class="col-md-7"> <div class="row"> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> </div> <div class="row"> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> <div class="col-md-3 mb-3"> <img src="https://picsum.photos/100/200"> </div> </div> </div> <div class="col-md-4"> </div> </div>

Remember : Mobile first.记住:移动优先。 Meaning that your columns will always start to 12 grids until told otherwise.这意味着您的列将始终从 12 个网格开始,除非另有说明。 So if you only define md, then it will get the md configuration from tablet and bigger screens.所以如果你只定义了 md,那么它将从平板电脑和更大的屏幕上获取 md 配置。

Now for your problem, you could use the offsets:现在对于您的问题,您可以使用偏移量:

<div class="col-sm-4 col-md-2 col-md-offset-1"></div>
<div class="col-sm-4 col-md-2"></div>
<div class="col-sm-4 col-md-2"></div>
<div class="col-sm-4 col-md-2"></div>
<div class="col-sm-4 col-md-2"></div>

Another way to do it, is to just not define any number and let it automatically fill the width:另一种方法是不定义任何数字并让它自动填充宽度:

<div class="row">
    <div class="col-sm-4 col-md"></div>
    <div class="col-sm-4 col-md"></div>
    <div class="col-sm-4 col-md"></div>
    <div class="col-sm-4 col-md"></div>
    <div class="col-sm-4 col-md"></div>
  </div>

It seems that you have more than 5 items meaning that you will have to iterate through them all and create a row with 5 children on each row.似乎您有 5 个以上的项目,这意味着您必须遍历所有项目并在每行上创建一个包含 5 个子项的行。 This might help you to achieve that:这可能会帮助您实现这一目标:

Loop through an array and divide it 循环遍历数组并将其划分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM