Flexbox div未在Chrome中显示

时间:2015-07-27 22:19:27

标签: html css google-chrome firefox flexbox

我试图设置一个简单的html布局,其中包含标题,侧边栏和地图的大div。出于某种原因,我在使用Mozilla Firefox时看到了所需的行为,但在Google Chrome中却没有。

到目前为止,我没有找到答案。

小提琴:https://jsfiddle.net/hporaozk/4/

HTML:

<div class="wrapper">
    <div class="header">HEADER</div>
    <div class="content">
        <div class="sidebar">
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
            <p>item</p>
        </div>
        <div class="map-container">
            <div class="map">actual map</div>
        </div>
    </div>
</div>

的CSS:

.wrapper{
    height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
}
.header{
    flex: 0 0 50px;
    width: 100%;
    background-color: #ff0000;
}

.content{
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: row;
}

.sidebar{   
    background-color: #00ff00;
    flex: 0 0 240px;
    height: 100%;
    overflow-y: scroll;
}

.map-container{
    flex: 1;
    height: 100%;
    position: relative;
}

.map{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #0000ff;
}

Chrome:Chrome Screenshot Firefox:Firefox Screenshot

2 个答案:

答案 0 :(得分:1)

在这里:DEMO

最重要的部分是将您的展示素品(.map-container.sidebar)设置为flex-basis: 50%,这是简写flex: 0 1 50%

您可以相应地调整它们。

CSS

.wrapper {
    height: 100vh;
    width: 100%;
    display: flex;
    display: -webkit-flex;
    flex-direction: column;
    -webkit-flex-direction: column;
}
.header {
    flex: 0 0 50px;
    width: 100%;
    background-color: #ff0000;
}
.content {
    flex: 1 0 100%;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: nowrap;
    flex-wrap: nowrap;
    -webkit-justify-content: space-around;
    justify-content: space-around;
    -webkit-align-content: flex-start;
    align-content: flex-start;
    -webkit-align-items: space-around;
    align-items: space-around;
}
.sidebar {
    background-color: #00ff00;
    -webkit-flex: 0 1 50%;
    flex: 0 1 50%;
    overflow-y: scroll;
}
.map-container {
    position: relative;
    -webkit-flex: 0 1 50%;
    flex: 0 1 50%;
}
.map {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: #0000ff;
}

答案 1 :(得分:0)

首先,如果您使用的是flex-box,我希望您始终使用前缀,否则您将有很多时髦的业务。

在这种情况下,您的问题很容易解决:

只需在.content上设置一个高度!

.content{
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: row;
    height: 100%; // add this
}