0

I was experimenting with flex-basis and accidentally came across an interesting thing. Wrap line when adding border to an inline-flex container. This behavior is the same in Firefox, Chrome and Opera browsers.

Questions:

  • Why is there no line wrap in Example 1.1?
  • Why is there a line wrap in example 1.2 and 1.3?
  • Why is the line wrap when adding border and not when adding padding? ( I suspect that this is spelled out somewhere in the standard )

Thank you.

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.container:nth-child(1) .flex .item:first-child{
    border: none;
}

.container:nth-child(3) .flex .item:first-child,
.container:nth-child(4) .flex .item
{
    box-sizing:content-box;
}

.flex {
    display: inline-flex;
    align-items: center;
}

.item {
    flex: 0 1 200px;
    padding: 0 5px;
    background: orange;
}

.item:first-child {
    border-right: 1px solid black;
}
<div class="container">
    <h2>1.1 inline-flex (padding)</h2>
    <div class="flex">
        <div class="item">flex: 0 1 200px;</div>
        <div class="item">flex: 0 1 200px;</div>
    </div>
</div>
<div class="container">
    <h2>1.2 inline-flex (border first item + padding + box-sizing: border-box)</h2>
    <div class="flex">
        <div class="item">flex: 0 1 200px;</div>
        <div class="item">flex: 0 1 200px;</div>
    </div>
</div>
<div class="container">
    <h2>1.3 inline-flex (border first item + padding + box-sizing: content-box first item)</h2>
    <div class="flex">
        <div class="item">flex: 0 1 200px;</div>
        <div class="item">flex: 0 1 200px;</div>
    </div>
</div>
<div class="container">
    <h2>1.4 inline-flex (border first item + padding + box-sizing: content-box both item)</h2>
    <div class="flex">
        <div class="item">flex: 0 1 200px;</div>
        <div class="item">flex: 0 1 200px;</div>
    </div>
</div>
i like Cola
  • 277
  • 6
  • 15
  • 1
    notice that in all your cases, flex-basis is not working. This is actually a bug (use width instead) – Temani Afif Aug 29 '21 at 21:18
  • 1
    check the "browser bug" section in the duplicate – Temani Afif Aug 29 '21 at 21:19
  • Hi Temani Afif (I read your articles on css-tricks=) ), I know that flex-basis does not work and it suits me. But I still have questions about line wrap – i like Cola Aug 30 '21 at 04:27
  • 1
    it's still related to the flex-basis behavior, if your remove flex-basis, all of them will have the same behavior so the behavior is related to the bug – Temani Afif Aug 30 '21 at 08:09

0 Answers0