简体   繁体   English

当使用flex时,Firefox会忽略元素的width属性

[英]Firefox ignores width property of element when using flex

I am trying to align some elements using different flex and width properties. 我正在尝试使用不同的flex和width属性来对齐某些元素。 In Safari and Chrome the behavior is as expected, but in firefox it is not. 在Safari和Chrome中,行为符合预期,但在Firefox中则并非如此。

It seems that the width property gets ignored, even though you set the width of the element to a very high, fixed value. 即使将元素的宽度设置为非常高的固定值,似乎width属性也被忽略了。

See example here: https://jsfiddle.net/wugrtwjc/ 在此处查看示例: https//jsfiddle.net/wugrtwjc/

The desired behavior is to have the two divs wrapped in the class "r-6" under each other, both covering the whole width of their parent (This is happening in Firefox and Chrome). 理想的行为是使两个div相互包裹在“ r-6”类中,两个div都覆盖其父对象的整个宽度(这在Firefox和Chrome中是发生的)。

In firefox the two divs is aligned next to each other even though the width is set to 100%. 在firefox中,即使将宽度设置为100%,两个div也仍然彼此对齐。 You can also try to set the width of this class to something like 10000px, but it will still only take up half of the space of its parent div. 您也可以尝试将此类的宽度设置为10000px,但它仍仅占据其父div的一半空间。

Html setup: 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: 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;
}

try this code 试试这个代码

<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>

Hope this helps.. 希望这可以帮助..

Take care and happy coding 保重和快乐编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM