野花--bootstrap一行平均分为5列
在用bootstrap4的时候,因为要分一行5列显示,但是如果直接设置为col-2,就无法完全居中,如果加justify-content-center,那么自动换行就无法从排列在左侧开始,如图
因此,在网上找到了一些大神写的一行5列的代码:
1 2 3 4 5 6 7 8 9 | <style> .col-xs -2 -half, .col-sm -2 -half, .col-md -2 -half, .col-lg -2 -half{ position : relative ; min-height : 1px ; padding-right : 10px ; padding-left : 10px ; } @media ( min-width : 768px ) { .col-sm -2 -half{ width : 20% ; float : left ; } } @media ( min-width : 992px ) { .col-md -2 -half{ width : 20% ; float : left ; } } @media ( min-width : 1200px ) { .col-lg -2 -half{ width : 20% ; float : left ; } } </style> |
上述的是bootstrap3的版本代码,根据自己所用的版本,更改媒体查询参数,以及float或者改为flex属性即可
bootstrap4 有另外一种简单的写法:使用 row-cols-xl-5 属性
1 2 3 4 5 6 7 8 9 10 11 | <div class= "container" > <div class= "row row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5" > <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> <div class= "bg-primary p-1 mb-3 border" style= "height: 60px" ></div> </div> </div> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通