html - 图像网格:桌面上为 5 x 5,移动设备上为 3 x 9
问题描述
我需要在桌面屏幕的 3/4 上制作 5 x 5 的图像网格,但在移动设备时是 3 x 9(最后一行只有 1 个图像)。
所有图像始终为 120x175。
所需桌面:
想要的手机:
我目前有一个 4 x 4 的网格,因为 Bootstrap 使用可被 3 或 4 整除的 col。
但问题是网格不适合移动设备。
当前桌面:
当前手机:
代码:
<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. So if you only define md, then it will get the md configuration from tablet and bigger screens.
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. This might help you to achieve that:
推荐阅读
- ajax - Ajax 参数始终为空
- elasticsearch - 在 ElasticSearch 中使用嵌套字段是否会扩展或有任何意外的陷阱?
- javascript - 有没有一种从邮政编码推断数字范围的好方法?
- amazon-web-services - DynamoDB 上聊天应用的单表设计,检查方向是否正确
- vue.js - VueJS 3 项目:“无法获取”消息,除根以外的所有路径
- javascript - 想要在散景中使用 TapTool 显示 HoverTool 工具提示数据
- c - 我可以在不使用 va_arg 函数的情况下遍历变量参数列表吗?
- css - 第三方@font-face 不起作用 - 未将字体应用于 H1 标签
- swiftui - 激活 contextMenu 时 UIViewRepresentable 视图消失
- php - 在回调函数中调用命名空间类的静态方法