I have a problem with a css grid layout.
The grid container is absolutely positioned and the grid-template-rows contains an 1fr to allow one row to take all the free space.
This displays correctly on all current browsers except the latest Safari installed with macOS 10.13.2
The issue seems to be caused by it not calculating the freespace if the height is not explicitly set.
Am I missing something or is there a workaround?
jsfiddle example
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: grid;
grid-template-rows: 1fr 150px;
grid-template-columns: 1fr 150px;
grid-template-areas: "a b" "c d";
}
.wrapper>div {
outline: solid 1px #aaa;
padding: 10px;
}
.game {
grid-area: a;
}
.player {
grid-area: b;
}
.rules {
grid-area: d;
}
.controls {
grid-area: c;
}
<div class="wrapper">
<div class="game">game</div>
<div class="player">player</div>
<div class="rules">rules</div>
<div class="controls">controls</div>
</div>
The supporting browsers Other than in Internet Explorer, CSS Grid Layout is unprefixed in Safari, Chrome, Opera, Firefox and Edge.
The height of the grid rows is set to 1fr so that it is proportional to the height of the grid. Some grid items have a grid-row: span 2 or grid-row: span 3 . The grid element is absolutely positioned inside of wrapper with padding on it in order to maintain the aspect ratio.
Most developers are afraid to start using CSS Grid because of browser support, but CSS grid is fully supported in all main browsers: Chrome, Firefox, Safari, Edge including their mobile versions.
As long as you structure your HTML so that the elements follow a logical order that makes sense when rendered without CSS, there is no reason why using absolute positioning should be considered bad practice.
In 2017 top: 0; bottom 0
is more like a dirty hack. Just give the .wrapper
a minimum height as 100% of the viewport - 100vh.
.wrapper {
min-height: 100vh;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With