【问题标题】:Firefox ignores width property of element when using flexFirefox 在使用 flex 时忽略元素的宽度属性
【发布时间】:2016-09-09 07:41:54
【问题描述】:

我正在尝试使用不同的 flex 和 width 属性对齐一些元素。在 Safari 和 Chrome 中,行为符合预期,但在 Firefox 中则不然。

似乎 width 属性被忽略了,即使您将元素的宽度设置为非常高的固定值。

请参见此处的示例: https://jsfiddle.net/wugrtwjc/

期望的行为是将两个 div 包裹在“r-6”类中,并在彼此下方,都覆盖其父级的整个宽度(这在 Firefox 和 Chrome 中发生)。

在 firefox 中,即使宽度设置为 100%,两个 div 也会彼此相邻对齐。您也可以尝试将此类的宽度设置为 10000px 之类的值,但它仍然只占用其父 div 的一半空间。

HTML 设置:

<div class="layout-row">
    <div class="c-l-8">
        <div class="layout-col h-800">
            <div class="r-6">
                 <div class="one"></div>
            </div>
            <div class="r-6">
                 <div class="two"></div>
            </div>
        </div>
    </div>
</div>

CSS:

.layout-row {
    -webkit-flex-flow: row wrap;
    width: 100%;
}

.layout-col {
  -webkit-flex-flow: column wrap;
}

.layout-row, .layout-col {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

.c-l-8 {
  width: 66.66667%;
}

.r-6 {
  width: 100%;
  height: 50%;
}

.h-800 {
  height: 800px;
}

.one, .two {
  width: 100%;
  height: 100%;
}

.one {
  background: red;
}

.two {
  background: blue;
}

【问题讨论】:

    标签: css firefox flexbox


    【解决方案1】:

    试试这个代码

    <style>
    
            .layout-row,
            .layout-col {
                display: -webkit-box;
                display: -moz-box;
                display: -ms-flexbox;
                display: -webkit-flex;
                display: flex;
            }
    
            .layout-row {
                flex-flow: row wrap;
                width: 100vw;
            }
    
            .layout-col {
                flex-flow: column wrap;
            }
    
            .c-l-8 {
                width: 100%;
            }
    
            .r-6 {
                width: 100%;
                height: 50%;
            }
    
            .h-800 {
                height: 800px;
            }
    
            .one,
            .two {
                width: 100%;
                height: 100%;
            }
    
            .one {
                background: red;
            }
    
            .two {
                background: blue;
            }
    
      </style>
    

    希望这会有所帮助..

    保重并快乐编码

    【讨论】:

    • 使用 flex-flow 而不是 -webkit-flex-flow 解决了问题:)
    • 很乐意提供帮助...确保最后有通用声明,因为如果浏览器已经开始接受通用请求,这将生效,否则浏览器特定的实现仍然可以工作...
    猜你喜欢
    • 2013-04-26
    • 2016-05-02
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 2018-10-04
    相关资源
    最近更新 更多