css两行1列框布局

时间:2014-01-29 22:34:33

标签: css css3 flexbox

我一直在使用flexbox进行两行和一列布局,我使用的是flexbox,因为我不认为css2.1可以填充box-B的剩余空间。在我的jsFiddle的例子中,我不能让box-C向右移动,而且我也不能让box-B垂直弯曲并填充内容,有人可以帮助我这个布局

jsFiddle here

enter image description here enter image description here

#container {
    background-color:red;
    width:100%; height:100%
}

#three-box-layout {
    display:flex;
    display:-ms-flex; 
    display:-webkit-flexbox; 
    display:-moz-flex; 
    height:100%;
    -ms-flex-direction:column;
    -webkit-flex-direction:column
}

.shuffle-box {

}
#box-a {
    background-color:#f601ff; -ms-flex-order:1; -webkit-flex-order:1;
    margin-right:30%;   
}
#box-b {
    -ms-flex:3;
    -webkit-flex:3;
    -moz-flex:3;
    flex:3;

    background-color:#37fe02;
    margin-right:30%;
}
#three-box-layout #box-c {
    -ms-flex:3;
    -webkit-flex:3;
    -moz-flex:3;
    flex:3;

    background-color:#02effe; 

    margin-left:70%; float:right;

}


<div id="container">
    <div id="three-box-layout">
        <div id="box-a" class="shuffle-box">
            <div style="height:425px; background-color:pink">A</div>                
        </div>
        <div id="box-b">B</div>
        <div id="box-c">C</div>
    </div>    
</div>

1 个答案:

答案 0 :(得分:1)

您可以使用CSS表格(不需要Flexbox)

调整浏览器大小以查看正在运行的媒体查询!

FIDDLE1(内容很少)/ FIDDLE2(很多内容)

标记

<div class="container">
    <div class="row1">
        <div>A</div>
        <div></div> /* give this div table cell 50% width on wide screens */
    </div>
    <div class="row2">
        <div>B</div>
        <div>C</div>
    </div>
</div>

CSS
--

.container {
    width: 800px;
    height: 500px;
    display:table;
    text-align: center;
    position: relative;
}
.row1 {
    display:table-row;
    max-height: 425px;
    background: pink;
}
.row1 div {
    display:table-cell;
    width:50%;
}
.row2 {
    display:table-row;
    height: 100%;
}
.row2 div {
    width: 100%;
    height: 100%;
    float:left;
    background: green;
}
.row2 div + div {
    background: aqua;
    width: 50%;
    height: 100%;
    position: absolute;
    top:0;
    right:0;
}
@media (max-width: 1024px) {
    .row1 {
        width: 100%;
    }
    .row1 div + div {
        display: none;
    }
    .row2 div {
        width: 50%;
    }
    .row2 div + div {
        position: static;
    }
}