html - 如何通过垂直居中保持第一行中的 3 个固定宽度项目和下一行中的 2 个固定宽度项目
问题描述
.content{
border:1px solid gray;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
}
.item{
background-color: green;
width: 50px;
max-width: 50px;
text-align: center;
}
.item.second{
margin:0 34.7%;
}
.item.fourth{
margin-left: calc(100%-50px) /*not works */
}
.item.fifth{
margin-right: calc(100%-50px) /*not works */
}
<div class="content">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
我想保留顶行的 3 个项目以及底行的 2 个项目。顶行是space-between
正确的。如何保持第二排space-around
?这都是固定宽度。
预期结果:
解决方案
尝试这个
.item{
width: calc(33% - 10%); /* margin left and right*/
max-width: calc(33% - 10%); /* margin left and right*/
margin:5%;
}
并添加justify-content: center;
到内容类。
.content{
border:1px solid gray;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
}
.item{
background-color: green;
width: calc(33% - 10%); /* margin left and right*/
max-width: calc(33% - 10%); /* margin left and right*/
text-align: center;
text-align: center;
flex-grow: 3;
flex-shrink: 0;
margin:5%;
}
<div class="content">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
推荐阅读
- angular - Kendo for Angular 的 k 选项
- jquery - 使用 Spring+Thymleaf 保持导航栏静态可用
- c# - C#如何等待异步任务,直到它指示继续
- javascript - 一次两个菜单都处于活动状态
- c# - 运行时默认值不相等
- mysql - 创建外键时出错:MySQL 错误 1215:无法添加外键约束
- ios - Xcode 10 Beta 6 Playground 中未调用 Deinit 方法
- regex - 正则表达式:PCRE 原子组不起作用
- sql - 如何使用 LISTAGG 和 Regexp_replace 获得不同的值
- c# - 删除某些控件后如何删除(删除)文本框之间的空格?