【问题标题】:nested flexbox not showing margin嵌套的 flexbox 不显示边距
【发布时间】:2015-06-13 21:53:06
【问题描述】:

我正在尝试显示嵌套的弹性框,以获得类似于 Excel 中的单元格合并的效果。我让嵌套单元格显示,但我无法正确显示边距:我希望所有边距都可见,而不仅仅是在主列之间。在这里摆弄 --> http://jsfiddle.net/bedhvee4/1/

<div class="flex-container">
    <div class="flex-item" style="-ms-flex: 4; flex: 4;">
        <div class="flex-container">
            <div class="flex-item" style="flex: 0 0 100%">Column A</div>
            <div class="flex-item">11</div>
            <div class="flex-item">12</div>
            <div class="flex-item">13</div>
            <div class="flex-item">14</div>
        </div>
        <div class="flex-container">
            <div class="flex-item">21</div>
            <div class="flex-item">22</div>
            <div class="flex-item">23</div>
            <div class="flex-item">24</div>
        </div>
    </div>
    <div class="flex-item" style="-ms-flex: 3; flex: 3;">
        <div class="flex-container">
            <div class="flex-item" style="flex: 0 0 100%">Column B</div>
            <div class="flex-item">16</div>
            <div class="flex-item">17</div>
            <div class="flex-item">18</div>
        </div>
        <div class="flex-container">
            <div class="flex-item">26</div>
            <div class="flex-item">27</div>
            <div class="flex-item">28</div>
        </div>
    </div>
</div>

        .flex-container {
        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;
        flex-wrap: wrap;
    }

    .flex-item {
        background: tomato;
        margin: 2px;
        color: white;
        font-weight: bold;
        font-size: 2.5vw;
        text-align: center;
        flex: 1 0 0px;
        white-space: nowrap;
        overflow: hidden;
    }

【问题讨论】:

    标签: css margin flexbox


    【解决方案1】:

    我并不是 100% 确定您在寻找什么,但我确实更改了一些颜色以及您嵌套 div 的顺序和边距似乎工作正常。这是jsfiddle

    http://jsfiddle.net/bedhvee4/6/

            .flex-container {
            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;
            flex-wrap: wrap;
            background: tomato;
        }
    
        .flex-item {
            padding: 10px;
            margin: 5px;
            background: blue;
            color: white;
            font-weight: bold;
            font-size: 2.5vw;
            text-align: center;
            flex: 1 0 0px;
            white-space: nowrap;
            overflow: hidden;
            border: 1px solid white;
        }
    

    【讨论】:

    • 谢谢你,Enjayy。不是我要找的东西,但你确实为我指明了正确的方向。看看这里更新的小提琴 --> jsfiddle.net/bedhvee4/7 我最终将容器的背景颜色设置为白色并删除了最后一个子列的右边距,所以边距现在正确对齐。
    • @Moto 真棒很高兴我能帮上忙!!
    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2021-11-26
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多