我正在尝试使用flexBox来构建同等大小的单元格的响应网格.如果单元格的内容相同,则我的代码可以工作,但如果单元格的内容长度不同,则代码不起作用 – 单元格会重新调整以适应其内容.
这就是我所追求的:
1.每个细胞宽度相同
2.调整浏览器大小时,每个单元格的宽度会自动调整.
这是关于小提琴的代码:https://jsfiddle.net/v0erefnd/1/
HTML:
<div class="flex-container"> <div class="flex-item">1</div> <div class="flex-item">100</div> <div class="flex-item">10,000</div> <div class="flex-item">1,000,000</div> <div class="flex-item">100,000</div> <div class="flex-item">10,000</div> </div> <div class="flex-container"> <div class="flex-item">100</div> <div class="flex-item">100</div> <div class="flex-item">100</div> <div class="flex-item">100</div> <div class="flex-item">100</div> <div class="flex-item">100</div> <div class="flex-item">100</div> </div>
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; }
谢谢!