5

We are working with CSS Grid, we realize there are other ways to get the following code to work, but we would like to use CSS Grid.

We have the following scenario, our CSS compiles to:

.r4 {
  grid-template-rows: var(--height-base) auto minmax(var(--height-base), -webkit-max-content) minmax(var(--height-base), -webkit-max-content);
  grid-template-rows: var(--height-base) auto minmax(var(--height-base), max-content) minmax(var(--height-base), max-content);
}

Autoprefixer has added -webkit prefix to max-content in the first property. This is expected and desired. However, when you try to render this CSS in Safari, Safari uses the second property (without -webkit prefix) and doesn't work properly.

I believe that Safari sees the properties having the same name and uses the latter.

Question: How should I use max-content so it works in Safari and Chrome? Is there a way to have Safari "choose" the correct property that includes the -webkit prefix for max-content or should I use max-content/min-content a different way?

Please see this codepen

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

:root {
  --height-base: 56px;
  --panels: 1;
  --panel-width: 100%;
}

::-webkit-scrollbar {
  display: none;
}

.grid-wrapper {
  background: black;
}

.panel {
  background: #6edde6;
}

.header {
  background: #0cf574;
}

.main {
  background: #15e6cd;
}

.post-content {
  background: #09C05B;
}

.footer {
  background: #1ccad8;
}

.grid-wrapper {
  display: grid;
  grid-template-columns: repeat(var(--panels), var(--panel-width));
  height: 100vh;
}

.panel {
  display: grid;
  height: inherit;
}

.column {
  display: grid;
  height: 100%;
}

.r4 {
  grid-template-rows: var(--height-base) auto minmax(var(--height-base), -webkit-max-content) minmax(var(--height-base), -webkit-max-content);
  grid-template-rows: var(--height-base) auto minmax(var(--height-base), max-content) minmax(var(--height-base), max-content);
}

.main {
  position: relative;
}

.main>.column {
  position: absolute;
  width: 100%;
  overflow: hidden;
}

.scrollable {
  overflow-y: auto !important;
}
<div class="grid-wrapper">
  <div class="panel r4">
    <div class="header">Header</div>
    <div class="main">
      <div class="column scrollable">
        <div>Main Content should be scrollable</div>
        <div>Autoprefixer adds minmax(var(--height-base), -webkit-max-content) for safari</div>
        <div>minmax(var(--height-base), max-content) -webkit- is not required otherwise</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
        <div>Main Content</div>
      </div>
    </div>
    <div class="post-content">
      Post Content should always be visible without scrolling, growing to accomadate its contents<br> Post Content<br> Post Content<br> Post Content<br> Post Content<br> Post Content<br> Post Content<br>
    </div>
    <div class="footer">Footer</div>
  </div>
</div>

Please compare on Chrome vs Safari to see why we need -webkit prefix for max-content, Chrome works as desired.

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
lilbumblebear
  • 67
  • 1
  • 7
  • Can't see your codepen. You should also post enough code in the question to reproduce the problem. – Michael Benjamin Jul 31 '17 at 16:44
  • Thank you Michael, I updated the link to the codepen. I wasn't sure the best way to add the code to the question so I made the codepen for demonstration. – lilbumblebear Jul 31 '17 at 17:40
  • I can't fully delve into your question because I'm at work. But on a cursory read, maybe this will help you: https://stackoverflow.com/q/36225219/3597276 – Michael Benjamin Jul 31 '17 at 17:47
  • That is helpful, but for grid-template-rows there is no webkit prefix, it is only needed for max-content "inside" of grid-template-rows – lilbumblebear Jul 31 '17 at 17:52
  • What versions of Safari are you targeting? – Michael Benjamin Jul 31 '17 at 17:54
  • We are using gulp to compile, this is what we have `autoprefixer({browsers: ['last 3 versions']})` – lilbumblebear Jul 31 '17 at 18:35
  • Grid support in Safari just began with the current version (10.1), which was released in March 2017. There is no support (prefixed or otherwise) for Grid in Safari before that. http://caniuse.com/#search=grid – Michael Benjamin Jul 31 '17 at 18:37

0 Answers0