scroll-grid-hack

Make relative width pseudo absolute for overflow: scroll

HTML

<section>
<h1>With width <span class="magic">magic</span></h1>
  <div class="flex-container outer">
    <div class="flex-container inner">
      <div class="GRID-HACK">
        <div class="scrollable-tabs">
          <div>Scroll me! βž” βž” βž”</div>
          <div>my container behaves...</div>
          <div>like it have an absolute width.</div>
          <div>Usually you have to set...</div>
          <div>some sort of <code>width: 400px</code></div>
          <div>but not today! πŸ’«</div>
        </div>
      </div>
      <div class="boring-button">βž•</div>
      <div class="boring-button">πŸ”Ž</div>
    </div>
    <div class="login">
      <div class="boring-button">πŸ‘€</div>
    </div>
  </div>
</section>

<section>
  <h1>Without any magic</h1>
  <div class="flex-container outer">
    <div class="flex-container inner">
      <div class="scrollable-tabs">
        <div>Scroll me! βž” βž” βž”</div>
        <div>my container behaves...</div>
        <div>like it have an absolute width.</div>
        <div>Usually you have to set...</div>
        <div>some sort of <code>width: 400px</code></div>
        <div>but not today! πŸ’«</div>
      </div>
      <div class="boring-button">βž•</div>
      <div class="boring-button">πŸ”Ž</div>
    </div>
    <div class="login">
      <div class="boring-button">πŸ‘€</div>
    </div>
  </div>
</section>

CSS

body {
  width: 500px;
  border-right: 4px solid blue;
}

.flex-container {
  display: flex;
  height: 40px;
}

.GRID-HACK { 
  /* MAKE IT PSEUDO ABSOLUTE */
  display: grid;
  grid-template-columns: 1fr;

  /* boring details... */
  flex-grow: 1;
  box-shadow: 0 0 0 3px red;
}

.scrollable-tabs {
  /* SCROLL MUST HAVE ABSOLUT WIDTH */
  overflow-x: scroll;

  overflow-y: hidden;
  display: flex;
  background: chartreuse;
}

.scrollable-tabs > div {
  flex-basis: 300px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

body {
  display: flex;
  justify-content: space-around;
  height: 100vh;
  margin: 0;
  padding: 8px;
  box-sizing: border-box;
  flex-direction: column;
  font-family: helvetica;
}

.boring-button {
  width: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

div {
  box-shadow: 0 0 0 1px;
  height: 40px;
}
code {
  margin-left: .5em;
}
.magic {
  color: darkred;
  font-weight: bold;
}

.flex-container.outer {
  padding: .5em;
  background: #eee;
}
.flex-container.outer > * {
  background: white;
}
.login {
  margin-left: 2em;
  box-shadow: none;
  background: white;
}