html - 空间不足/窗口调整大小时将元素换行?
问题描述
我在父 div 中有 6 个框,如下所示:
- - - - - Parent Div - - - - -
div div div div div div
- - - - - Parent Div - - - - -
使用 display flex 将它们隔开。
但是,在调整窗口大小时,我希望它们折叠到 3 x 3,然后是 2 x 2。最后是:
- - - - - Parent Div - - - - -
Div Div
Div Div
Div Div
这是我尝试过但似乎无法正常工作的方法。我最终还是把 6 个挤在一起排成一排。
CSS:
.premium_listing_container {
width: 990px;
height:auto;
position: relative;
text-align: center;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.premium_component {
width:145.5px;
padding:0.4em;
vertical-align: top;
border:1px solid #878787;
text-align:center;
position:relative;
cursor: pointer;
margin-bottom:20px;
}
请问有人可以告诉我我哪里出错了吗?提前致谢。
解决方案
实际上,我设法在不使用媒体查询的情况下完成了我需要做的事情。通过利用 inline-block 显示属性。
我将暂缓接受我的答案,以允许其他人提供(更好的)答案 - 以防万一。
.premium_listing_container {
position: relative;
text-align: center;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.premium_component {
width:145.5px;
padding:0.4em;
vertical-align: top;
border:1px solid #878787;
text-align:center;
position:relative;
cursor: pointer;
margin-bottom:20px;
display: inline-block;
}
推荐阅读
- css - 多个css @media(最大宽度:)不起作用
- python-3.x - python区分大小写禁用并获取eual字符串
- authentication - 使用 oidc 的 JWT 使用不同数量的客户端进行身份验证
- python - 如何使用 selenium python 在 facebook 上单击“添加朋友”按钮
- javascript - 响应式导航栏(移动设备问题)
- regex - HTML 模式正则表达式字符之间至少有一个空格
- java - 在大数据(数千行和列)的情况下,为每个单元格设置 CellStyle()
- javascript - Javascript - 如何将提示输入添加到数组中以及是否被取消
- javascript - 将 2 个 JavaScript 合并为 1 个
- algorithm - 缓存抖动效应因大数据大小而降低