【问题标题】:Flexbox div not showing in ChromeFlexbox div 未在 Chrome 中显示
【发布时间】:2015-10-18 07:12:43
【问题描述】:

我正在尝试为地图设置一个带有标题、侧边栏和大 div 的简单 html 布局。出于某种原因,我在使用 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;
}

铬: 火狐:

【问题讨论】:

    标签: html css google-chrome firefox flexbox


    【解决方案1】:

    首先,我希望你在使用 flex-box 时总是使用前缀,否则你会遇到很多时髦的事情。

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

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

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

    【讨论】:

    【解决方案2】:

    给你: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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 2018-09-07
      • 1970-01-01
      • 2016-01-25
      • 2020-09-12
      • 2020-08-22
      • 2016-05-14
      • 2015-11-19
      • 2014-05-20
      相关资源
      最近更新 更多