TL;DR: Codepen https://codepen.io/veleek/pen/YmJGjY shows that grid cell with display: none
seems to cause adjacent cell to take up less space instead of collapsing to nothing.
I'm creating a simple CSS Grid layout with a banner at the top with a logo, title, link bar, and a content block underneath.
For pages without nav links I'd like to collapse the nav section so that the title takes up the entire space. Effectively I want that grid cell to be 0px tall.
Unfortunately, when I set display: none
on that cell, it disappears but it seems to take up MORE space. This actually causes the title to collapse itself down to be SMALLER then when that cell is present.
The image size is not fixed at 150px and I'd prefer to avoid fixed sizes if possible. I just want to force that grid row to have 0 height when it's empty. I've tried a bunch of combinations of display:block/flex
, align-items/justify-content/etc.: stretch/center/etc.
but nothing seems to work.
I've got a CodePen showing the issue here: https://codepen.io/veleek/pen/YmJGjY