28

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

  • In chromium: normal, chome
  • In firefox 34: firefox 34, bad

Is it bug? Or normal working? What do i need to change to fix it? Why #flex don't resize properly?

HTML:

<div id="outer">
    <div id="flex">
        <label>123</label>
        <input type="text" value="some text" />
    </div>
</div>  

CSS:

#outer { display: flex; }

#flex {
    display: flex;
    border: 1px solid green;
    outline: 1px solid red;
}

label { flex: 0 0 80px; }
faiwer
  • 1,808
  • 1
  • 15
  • 17
  • 3
    `input { min-width: 1px; }` fix problem. `-moz-min-content`... – faiwer Dec 11 '14 at 14:43
  • Thank you for asking this. I see this behaviour in our system maybe since version 33 or 32. Please mention the box-sizing model you use because I think the problem has to do with it. – Ashraf Sabry Dec 14 '14 at 08:11
  • @AshrafSabry, content-box – faiwer Dec 15 '14 at 13:30
  • possible duplicate of [How can I get FF 33.x Flexbox behavior in FF 34.x?](http://stackoverflow.com/questions/26895349/how-can-i-get-ff-33-x-flexbox-behavior-in-ff-34-x) – Oriol May 17 '15 at 16:44
  • Is there a reason http://jsfiddle.net/944tL115/20/ cannot work? Just set the width attribute directly? – Coder Sep 25 '15 at 07:13

5 Answers5

50

Fix:

input { min-width: 1px; }

For vertical direction - min-height;

faiwer
  • 1,808
  • 1
  • 15
  • 17
5

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>
Community
  • 1
  • 1
misterManSam
  • 24,303
  • 11
  • 69
  • 89
  • 2
    Did Mozilla acknowledge this as a bug? Is it mentioned on their bug tracker? My flexbox UI was working well on Firefox until version 32 or 33 or 34 (not sure because I was using the developer edition which is two versions ahead the release version) – Ashraf Sabry Dec 14 '14 at 08:35
  • also interested in @AshrafSabry's question above; can anyone confirm that this is indeed a bug? – J. Ed Dec 15 '14 at 09:59
  • 3
    @AshrafSabry Its due to a spec change: https://developer.mozilla.org/en-US/Firefox/Releases/34/Site_Compatibility#CSS – sergio91pt Dec 21 '14 at 14:00
  • @sergio91pt - Good find. So not a bug at all and I don't think my answer is that useful anymore. Could you add your comment underneath the accepted answer where it will be seen? I'll edit it in to that answer later and delete this post. – misterManSam Dec 21 '14 at 14:06
5

variant with

min-width: 0

also works

3

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>
Weafs.py
  • 22,731
  • 9
  • 56
  • 78
  • added to comment (below answer) strange "solution": `input { min-width: 1px; }`... working. Bug or not bug? :) – faiwer Dec 11 '14 at 14:45
  • @faiwer - Great! And yea strange solution. I wouldn't say its a bug, its just how different browsers render the elements. – Weafs.py Dec 11 '14 at 14:47
0

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 {}
Pixel Rubble
  • 1,104
  • 3
  • 14
  • 26
  • you lost problem :) `label` without `flex-basis`, `form` without `display: flex`. my minimal jsfiddle codes had it. current version without `display: flex` for label (mistake) - http://jsfiddle.net/944tL115/4/ – faiwer Dec 11 '14 at 14:42