2

I'm trying to create a layout with CSS grid that looks like this (ie: a section on the left that has a fixed width and height, a section at the top which takes up the minimum height possible, and a section underneath that which takes up all the remaining space):

enter image description here

However, what I'm getting is this (where the space at the bottom of the orange section is equal to the grid-row-gap):

enter image description here

I'm wondering why the fr is being calculated like this instead of compensating for the grid gap?

(In my project I can fix this issue by adding a margin to the bottom right element instead of using grid-row-gap, but I'd like to know if there's something I'm misunderstanding about CSS grid)

span {
  display: inline-block;
}

.grid {
  border: 1px solid black;
  display: inline-grid;
  grid-template-columns: repeat(2, auto);
  grid-template-rows: auto 1fr;
  grid-row-gap: 1rem;
}

.left {
  background: orange;
  height: 120px;
  width: 120px;
  grid-row: 1/span 2;
}

.right-top {
  background: yellow;
  height: 20px;
  width: 300px;
}

.right-bottom {
  background: blue;
}
<div class="grid">
  <span class="left"></span>
  <span class="right-top"></span>
  <span class="right-bottom"></span>
</div>
Andrea Crawford
  • 321
  • 2
  • 10
  • 1
    ...but the demo doesn't show the issue. Cannot replicate. Is this browser specific? – Paulie_D May 16 '18 at 08:59
  • @Paulie_D in Chrome and Firefox on Linux the demo shows the issue (the layout appears as in the second screenshot). How is it appearing for you? – Andrea Crawford May 16 '18 at 09:31
  • 1
    @AndreaCrawford checked on mac for all browsers it looks fine. – Anmol Sandal May 16 '18 at 09:51
  • @AnmolSandal weird... thank you – Andrea Crawford May 16 '18 at 09:58
  • I guess you are using Linux – Andre Barbosa May 16 '18 at 10:05
  • Seems like that would happen if the blue box had a fixed height or it's height is bigger than the red box. – Rainbow May 16 '18 at 11:06
  • @ZohirSalakCeNa the blue box doesn't have a fixed height, it seems like this is an issue specific to Chrome/Firefox on Linux – Andrea Crawford May 16 '18 at 11:15
  • Why don't you check the devTools and what's causing that space to appear. – Rainbow May 16 '18 at 11:20
  • 2
    Check in Windows for Chrome & FF - cannot replicate. IE...meh! – Paulie_D May 16 '18 at 11:42
  • 1
    In FF Windows your layout works fine. The problem occurs in Chrome Windows. There are a growing number of questions being posted about unwanted Grid gaps in Chrome. Also, *it's not certain that `grid-gap` properties are the source of the problem*. Here's a related post: https://stackoverflow.com/q/50262606/3597276 – Michael Benjamin May 16 '18 at 15:25
  • I was unable to replicate the problem. Is it still an issue? Test: go to stack overflow page and run Code Snippet tool Check if orange box files the left box as expected Windows 10 (Preview) Chrome Version 66.0.3359.181 -pass Firefox 60.0.1 (64 bit) -pass Firefox Developer 61 -pass Edge Microsoft EdgeHTML 17.17677 -pass IE 11 fails in a number of ways as expected Ubuntu 17.10 Chrome Version 66.0.3359.181 (Official Build) (64-bit) -pass Firefox 61b05 -pass – JohnC May 27 '18 at 10:34
  • Still happening on Linux Mint 18.3 -- Chrome Version 65.0.3325.181 (Official Build) (64-bit) & Firefox 57.0 (64 bit) (Mozilla Firefox for Linux Mint) – Andrea Crawford May 29 '18 at 15:29

0 Answers0