1

The following makes the flex items overflow:

#container {
  display: inline-flex;
  border: 1px dashed blue
}

#container div {
  flex: 0 0 120px;
  border: 1px dashed orange
}
<div id="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

I thought inline-flex in general tries to accommodates all items into its width?

The following works:

#container {
  display: inline-flex;
  border: 1px dashed blue
}

#container div {
  width: 120px;
  border: 1px dashed orange
}
<div id="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

What rules specify this behavior and how should you usually think about it when designing?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • actually this is considered as a bug (even if I am not convinced at 100%) ... check the section *flex-basis fails in Chrome and Firefox when the grandparent container is a shrink-to-fit element.* in the duplicate. The same issue happen if the container or any upper container is shrink-to-fit – Temani Afif Jan 04 '20 at 15:39
  • over there in the duplicate question, it is like a whole section of textbook there, together with perhaps, maybe, and a ton of cases. It doesn't really directly answer this question – nonopolarity Jan 04 '20 at 15:40
  • it is a bug... even 4 years later after that question and 10 years after the first flexbox specs came out? And is present in Chrome, Firefox, and all major browsers? – nonopolarity Jan 04 '20 at 15:43
  • The duplicate is the canonical one dealing with the difference between flex-basis and width. It also contain all the particular cases and bugs. It doesn't directly answer this question but it cover more than this question. Your case is listed there and covered by two sections – Temani Afif Jan 04 '20 at 15:43
  • if you point me to https://www.w3.org/TR/css-flexbox-1/ it also contains the answer but it doesn't help – nonopolarity Jan 04 '20 at 15:44
  • because the specification doesn't detail this behavior and the other answer does. Also don't consider the date of the question but the one of the answer because it's constantly updated to cover any particular case, bug, etc – Temani Afif Jan 04 '20 at 15:46
  • I really wonder if somebody has a better answer than the duplicate. Right now if I visit this question on Firefox it directly sends me to the duplicate, which really doesn't help – nonopolarity Jan 04 '20 at 15:49
  • This one https://jsfiddle.net/h0qts3yk/2/ does behave differently in Chrome vs MS Edge... oh maybe there is a single rule that is not following by Chrome or MS Edge I am not sure. I thought the browser incompatibilities have been minimized but we have this basic one just for a flex item's flex-basis. But Chrome, Firefox, and Safari with Blink, Gecko, and Webkit all behave the same, while EdgeHTML behave differently. So the guess would be Edge not following some rule in the specs – nonopolarity Jan 04 '20 at 15:55
  • this is also explained in the duplicate : *But when the width property is used instead of flex-basis, the container respects the sizing of its children and expands accordingly. This is not a problem in IE11 and Edge.* – Temani Afif Jan 04 '20 at 15:57
  • I am a little surprised. So if it takes 3, 4 years to make Chrome/Firefox/Safari vs Edge behave the same, then all the developers have to use the `width` method, and 3, 4 years later, we still have to use the `width` method because we need the old browsers to become "unsupported" – nonopolarity Jan 04 '20 at 16:01
  • meanwhile, it is said that Jan 15, 2020 will be the date that the next Edge is released, and is based on Blink / Chromium. So then they may unify... also Edge seems like making its way back to MacOS – nonopolarity Jan 04 '20 at 16:12

0 Answers0