作者:真实的小莹_808 | 来源:互联网 | 2023-05-19 18:07
我正在尝试使用flexbox来构建一个大小相同的响应网格.如果单元格的内容相同,我的代码可以工作,但如果单元格的内容长度不同,则代码不起作用 - 单元格会重新调整以适应其内容.
这就是我所追求的:
1
.每个单元格宽度相同2.每个单元格的宽度在浏览器调整大小时自动调整.
这是我的小提琴代码:https://jsfiddle.net/v0erefnd/1/
HTML:
1
100
10,000
1,000,000
100,000,000
10,000,000,000
1,000,000,000,000
100
100
100
100
100
100
100
CSS:
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row;
justify-content: space-around;
height: 50px;
line-height:30px;
}
.flex-item {
/*todo: how to prevent the flexbox to resize to accommodate the text?*/
background: tomato;
margin: 10px 5px;
color: white;
font-weight: bold;
font-size: 1.5em;
text-align: center;
flex-grow: 1;
overflow: hidden;
}
谢谢!
1> Josh Crozier..:
如果您希望所有flexbox项具有相同的宽度,可以添加flex-basis: 100%
:
更新的示例
.flex-item {
background: tomato;
margin: 10px 5px;
color: white;
font-weight: bold;
font-size: 1.5em;
text-align: center;
flex-basis: 100%;
overflow: hidden;
}
我会使用`flex-basis:0px`代替(更有意义)或短缺`flex:1 0 0px`,但+1