Flex item with `max-width` and `max-height` causes the text next it to break unnecessarily in Chrome

Viewed 173

In the snippet below, the tab__icon has a max-width and a max-height, but apparently its causes the text inside of the tab__label next to it to break, while there's actually plenty of space.

I know it's the presence of both max-width and max-height that's causing this problem, because as soon as you change either max-width to width or max-height to height, the text no longer breaks, and everything works as expected.

What am I doing wrong here?

I also tried adding flex-shrink: 0; to tab__label but that would cause the text to overflow the parent, which is not what I want.

.tab-list {
  display: flex;
  width: 100%;
  border: 2px solid red;
  justify-content: space-around;
}

.tab-list__item {
  flex-shrink: 0;
}

.tab {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background-color: gray;
}

.tab__icon {
  max-width: 12px;
  max-height: 12px;
  flex-shrink: 0;
  margin-right: 5px;
}
<div class="tab-list">
  <div class="tab tab-list__item">
    <svg class="tab__icon" viewBox="0 0 11.25 15"> <g transform="translate(-3)"> <path d="M9.75,7.5A3.75,3.75,0,1,0,6,3.75,3.75,3.75,0,0,0,9.75,7.5Zm0-6.25a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,9.75,1.25Z" transform="translate(-1.125)"></path> <path d="M8.625,14A5.631,5.631,0,0,0,3,19.625a.625.625,0,1,0,1.25,0,4.375,4.375,0,1,1,8.75,0,.625.625,0,0,0,1.25,0A5.631,5.631,0,0,0,8.625,14Z" transform="translate(0 -5.25)"></path> </g> </svg>
    <span class="tab__label">Some title here</span>
  </div>
  
  <div class="tab tab-list__item">
    <svg class="tab__icon" viewBox="0 0 11.25 15"> <g transform="translate(-3)"> <path d="M9.75,7.5A3.75,3.75,0,1,0,6,3.75,3.75,3.75,0,0,0,9.75,7.5Zm0-6.25a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,9.75,1.25Z" transform="translate(-1.125)"></path> <path d="M8.625,14A5.631,5.631,0,0,0,3,19.625a.625.625,0,1,0,1.25,0,4.375,4.375,0,1,1,8.75,0,.625.625,0,0,0,1.25,0A5.631,5.631,0,0,0,8.625,14Z" transform="translate(0 -5.25)"></path> </g> </svg>
    <span class="tab__label">Some other title</span>
  </div>
</div>

Update: As @TemaniAfif pointed out in the comments, this problem only exists in Chrome, Firefox seems to work as expected.

2 Answers

Since you are fixing the width to a max value, you can set any value for width bigger than that. At least, it should make this working on Chrome since it's already fine on Firefox

.tab-list {
  display: flex;
  width: 100%;
  border: 2px solid red;
  justify-content: space-around;
}

.tab-list__item {
  flex-shrink: 0;
}

.tab {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  background-color: gray;
}

.tab__icon {
  max-width: 12px;
  max-height: 12px;
  flex-shrink: 0;
  margin-right: 5px;
  width:100px;
}
<div class="tab-list">
  <div class="tab tab-list__item">
    <svg class="tab__icon" viewBox="0 0 11.25 15"> <g transform="translate(-3)"> <path d="M9.75,7.5A3.75,3.75,0,1,0,6,3.75,3.75,3.75,0,0,0,9.75,7.5Zm0-6.25a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,9.75,1.25Z" transform="translate(-1.125)"></path> <path d="M8.625,14A5.631,5.631,0,0,0,3,19.625a.625.625,0,1,0,1.25,0,4.375,4.375,0,1,1,8.75,0,.625.625,0,0,0,1.25,0A5.631,5.631,0,0,0,8.625,14Z" transform="translate(0 -5.25)"></path> </g> </svg>
    <span class="tab__label">Some title here</span>
  </div>
  
  <div class="tab tab-list__item">
    <svg class="tab__icon" viewBox="0 0 11.25 15"> <g transform="translate(-3)"> <path d="M9.75,7.5A3.75,3.75,0,1,0,6,3.75,3.75,3.75,0,0,0,9.75,7.5Zm0-6.25a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,9.75,1.25Z" transform="translate(-1.125)"></path> <path d="M8.625,14A5.631,5.631,0,0,0,3,19.625a.625.625,0,1,0,1.25,0,4.375,4.375,0,1,1,8.75,0,.625.625,0,0,0,1.25,0A5.631,5.631,0,0,0,8.625,14Z" transform="translate(0 -5.25)"></path> </g> </svg>
    <span class="tab__label">Some other title</span>
  </div>
</div>

Mine is working just fine.

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

body {
  height: 100vh;
  display: grid;
  place-items: center;
}

.container {
  width: 90%;
  display: flex;
  align-items: center;
  border: 2px solid red;
  justify-content: space-around;
}

.container .tab {
  display: flex;
  padding: 10px 20px;
  align-items: center;
  background-color: #eee;
}
<div class="container">
  <div class="tab">
    <span>
      <svg viewBox="0 0 24 24" width="24" height="24">
        <path d="M12 2a5 5 0 1 0 5 5 5 5 0 0 0-5-5zm0 8a3 3 0 1 1 3-3 3 3 0 0 1-3 3zm9 11v-1a7 7 0 0 0-7-7h-4a7 7 0 0 0-7 7v1h2v-1a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v1z"></path>
      </svg>
    </span>
    <label>Some title here</label>
  </div>
  <div class="tab">
    <span>
      <svg viewBox="0 0 24 24" width="24" height="24">
        <path d="M12 2a5 5 0 1 0 5 5 5 5 0 0 0-5-5zm0 8a3 3 0 1 1 3-3 3 3 0 0 1-3 3zm9 11v-1a7 7 0 0 0-7-7h-4a7 7 0 0 0-7 7v1h2v-1a5 5 0 0 1 5-5h4a5 5 0 0 1 5 5v1z"></path>
      </svg>
    </span>
    <label>Some other title</label>
  </div>
</div>

Related