CSS Safari 14 issues with child elements blowing out in heigh when contained within a grid within a flex box

Viewed 2151

In the following markup below Col1 and Col2 inside the grid will blow out in height on MacOS Safari 14. What's interesting is that it blows out (off screen) by the exact height of the div above the grid. Is this a Safari bug and are there any work arounds OR have I missed something in my CSS?

Screenshot from MacOS Safari 14 Screenshot from MacOS Safari 14

Screenshot from Chrome Screenshot from Chrome

<!DOCTYPE html>
<html lang="en" class="h-full">
    <style>
      html,
      body {
        height: 100%;
        margin: 0;
      }
      .h-full {
        height: 100%;
      }
      .h-10 {
        height: 2.5rem;
      }
      .min-h-0 {
        min-height: 0;
      }
      .flex {
        display: flex;
      }
      .flex-col {
        flex-direction: column;
      }
      .flex-auto {
        flex: 1 1 auto;
      }
      .grid {
        display:grid;
      }
      .grid-cols-3{
        grid-template-columns: repeat(3, minmax(0, 1fr))
      }
      .col-span-1{
        grid-column: span 1 / span 1;
      }
      .flex-initial {
        flex: 0 1 auto;
      }
      .bg-green {
        background-color: rgb(12, 236, 12);
      }
      .bg-pink {
        background-color: rgb(248, 47, 255);
      }
      .bg-blue {
        background-color: rgb(110, 230, 252);
      }
      .bg-yellow {
        background-color: yellow;
      }
    </style>
  </head>
  <body class="h-full">
    <div id="sapper" class="h-full">
      <div class="flex flex-col h-full">
        <header class="flex-initial">
          Navigation
        </header>
        <main class="flex-auto h-full flex flex-col">
          <div class="flex-initial h-10 bg-yellow">
            Middle
          </div>
          <div class=" bg-pink grid grid-cols-3 flex-auto min-h-0">
            <div class="col-span-1 bg-green">Col 1</div>
            <div class="col-span-1 bg-blue">Col 2</div>
          </div>
        </main>
      </div>
    </div>
  </body>
</html>

2 Answers

Testing the given code on IOS 14 Safari also gives the overflow problem.

I came across this documentation on display: -webkit-inline-box; which discussed a (even then) outdated -webkit-inline-box setting.

If you apply this to the div containing the two columns and set each of those columns to 33.33% width (as the repeat(3...) setting seemed to then be being ignored) the correct result is obtained.

This seems rather (well, really) hacky as it's using an outdated setting which seems to just work in Safari -but for how long - and seems not to upset the other browsers.

Tested on Window 10 - Chrome, Edge, Firefox - and on iPadIOS 14 - Safari.

Just in case it is useful to be going on with here is the given code with these two additions (deliberately put in as inline styles to make it clear what has been added).

<!DOCTYPE html>
<html lang="en" class="h-full">
    <style>
      html,
      body {
        height: 100%;
        margin: 0;
      }
      .h-full {
        height: 100%;
      }
      .h-10 {
        height: 2.5rem;
      }
      .min-h-0 {
        min-height: 0;
      }
      .flex {
        display: flex;
      }
      .flex-col {
        flex-direction: column;
      }
      .flex-auto {
        flex: 1 1 auto;
      }
      .grid {
        display:grid;
      }
      .grid-cols-3{    
        grid-template-columns: repeat(3, minmax(0, 1fr))
      }
      .flex-inital {
        flex: 0 1 auto;
      }
      .bg-green {
        background-color: rgb(12, 236, 12);
      }
      .bg-pink {
        background-color: rgb(248, 47, 255);
      }
      .bg-blue {
        background-color: rgb(110, 230, 252);
      }
      .bg-yellow {
        background-color: yellow;
      }
    </style>
  </head>
  <body class="h-full">
    <div id="sapper" class="h-full">
      <div class="flex flex-col h-full">
        <header class="flex-initial">
          Navigation
        </header>
        <main class="flex-auto h-full flex flex-col">
          <div class="flex-inital h-10 bg-yellow">
            Middle
          </div>
          <div class=" bg-pink grid grid-cols-3 flex-auto min-h-0" style="display:-webkit-inline-box;">
            <div class=" bg-green" style="width:33.33%;">Col 1</div>
            <div class=" bg-blue" style="width:33.33%;">Col 2</div>
          </div>
        </main>
      </div>
    </div>
  </body>
</html>

I've tested this on Safari 14.1.1 and the issue appears to have been fixed.

Related