Firefox, Flexbox & overflow

后端 未结 5 1693
伪装坚强ぢ
伪装坚强ぢ 2020-12-24 03:03

After last firefox-update some of css3-code has been broken... Example (jsfiddle).

  • In chromium: \"normal,
相关标签:
5条回答
  • 2020-12-24 03:45

    Display: flex; only needs to be on the container that needs to be flexible, not the inner elements. Here's the updated CSS, if you need a specific width, you can set that on form {}.

    CSS

    form {}
    
    #flex {
        display: flex;
        border: 1px solid green;
        outline: 1px solid red;
    }
    
    #flex > * {
        flex: 1;
    }
    
    label {}
    
    input {}
    
    0 讨论(0)
  • 2020-12-24 03:46

    variant with

    min-width: 0
    

    also works

    0 讨论(0)
  • 2020-12-24 03:48

    Fix:

    input { min-width: 1px; }
    

    For vertical direction - min-height;

    0 讨论(0)
  • 2020-12-24 03:59

    There is a bug in Firefox 34. One of the elements is not playing nicely as a flex child, and the input seems to be too wide. This extra width is not taken into account by the flex containers green border.


    This can be confirmed as a bug because in Firefox 33.1 (and Chrome / IE) there is no problem with your example:

    Your Example Firefox 33.1

    Working Fine

    Your Example Firefox 34.0.5 — The input width is miscalculated by the flex container and the input itself cannot be given a smaller width.

    Not working


    As a workaround, we can set a width on the label; this width is recognised by the container and the bug is prevented in Firefox 34. In order to be used only in Firefox, we can set the width using the -moz- prefix with calc:

    label {
        width: -moz-calc(80px);
    }
    

    (Obviously previous versions of Firefox will also recognise this width)

    Bug Workaround Example

    Using inline-flex

    From your example, it looks like you want to use inline-flex in order to contain the width of the form to the width of its children. I have used this and removed the extra div that is no longer needed. There is a big difference in input widths per browser (this is consistent with the example in your question).

    Firefox 33

    Old Firefox Screenshot

    Firefox 34

    Firefox Example

    Chrome

    Chrome Screenshot

    IE11

    IE Example

    form {
      display: inline-flex;
      border: solid 1px green;
      outline: 1px solid red;
    }
    label {
      flex: 0 0 80px;
      width: -moz-calc(80px);
    }
    <form>
      <label>123</label>
      <input type="text" value="some text" />
    </form>

    0 讨论(0)
  • 2020-12-24 04:02

    What you could do is, subtract 80px from 100% and set that a width for input. Additionally, add box-sizing: border-box to prevent overflow.

    form {
      display: flex;
    }
    #flex {
      display: flex;
      border: 1px solid green;
      outline: 1px solid red;
    }
    label {
      display: flex;
      flex: 0 0 80px;
    }
    input {
      width: calc(100% - 80px);
      box-sizing: border-box;
    }
    <form>
      <div id="flex">
        <label>123</label>
        <input type="text" value="some text" />
      </div>
    </form>

    0 讨论(0)
提交回复
热议问题