热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

flexbox-在指定flex-grow值时阻止增加宽度

如何解决《flexbox-在指定flex-grow值时阻止增加宽度》经验,为你挑选了1个好方法。

我正在尝试使用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
推荐阅读
author-avatar
真实的小莹_808
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有