html - How to force a maximum amount of boxes in a row in flex?
问题描述
I have 4 total items that I want to display on a page. Two items on top and 2 below. The ones on the bottom dimensions need to be different from the ones on top. I am using flexbox to do this. The problem is, on a wide monitor the third item keeps wrapping to the top row. Here is my code.
.dashboard {
&-inner {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-content: center;
min-height: 100vh;
margin-top: $reporting-report-offset-top;
max-width: 1900px;
&-grid {
display: flex;
flex-flow: row wrap;
justify-content: center;
align-content: center;
overflow: hidden;
max-height: 100%;
margin: 0 auto;
max-width: 1900px;
&-item {
margin: $reporting-view-spacing;
// &-1 {
// min-width: 50%;
// }
&-2 {
// min-width: 50%;
// margin-right: 100px
}
&-3 {
max-width: 238px !important;
margin-right: 8px;
height: 687px !important;
}
The top two items will take 50% of the available width(margins included) the third item is intended to take approximately 25% of the bottom row and the 4th item the other 75%. How do I force the bottom item to the second row and stop it from wrapping to the top?
解决方案
这是一种设置元素样式以在 flex 元素中添加换行符的方法。
.separator {
content: '';
width: 100%;
}
.boxes {
display: flex;
flex-flow: row wrap;
}
.box {
height: 100px;
background: red;
border: 1px solid black;
box-sizing: border-box;
}
.box--25 {
width: 25%;
}
.box--50 {
width: 50%;
}
.box--75 {
width: 75%;
}
.separator {
content: '';
width: 100%;
}
<div class="boxes">
<div class="box box--50"></div>
<div class="box box--50"></div>
<br class="separator" />
<div class="box box--25"></div>
<div class="box box--75"></div>
</div>
推荐阅读
- html - 当浏览器窗口宽度小于 400 像素时,正文宽度不是 100%
- reactjs - 如何在 React 组件中使用 ckeditor 完整版
- excel - 用于复制/粘贴的 VBA 代码仅暂时有效
- python - pyinstaller 转换后无法打开 .exe
- java - 关闭连接后使用结果集数据
- python-3.x - 通过迭代特征选择和设置范围创建布局 PDF
- android - RecyclerView 没有显示来自 json 数组的数据
- intellij-idea - 使用 Blaze 进行 IntelliJ Python 调试
- python - 'headers' 参数对 python 请求库中的重定向有效吗?
- r - How to shift a column values based on column with logical value in R