Why is CSS Grid row height different in Safari?Chrome / Safari not filling 100% height of flex parentWhy is percentage height not working on my div?CSS 100% height with padding/marginMake a DIV fill an entire table cellHow can I transition height: 0; to height: auto; using CSS?How to make flexbox children 100% height of their parent?Twitter bootstrap 3 two columns full heightItems that span all columns/rows using CSS grid layoutCSS Grid Row Height Safari BugCSS Grid and Absolute Positioning on SafariCSS Grid does not work in Firefox and SafariCSS grid items overflow grid container when using “align-content: space-between” and a sticky header
This LM317 diagram doesn't make any sense to me
Is it possible to complete a PhD in CS in 3 years?
Replacement for Thyme
Number of states in taxi environment (Dietterich 2000)
How to evaluate the performance of open source solver?
Cannot update APT list: "repository no longer has a Release file"
Shrinking padding of node with label options
How does Kaya's Ghostform interact with Elenda, the Dusk Rose?
How to convert diagonal matrix to rectangular matrix
Simplicial manifold associated to Lie groupoid
How was the Shuttle loaded and unloaded from its carrier aircraft?
How was 'fissiparus' mistakenly analogized with 'vīviparus'?
What factors could lead to bishops establishing monastic armies?
How does one acquire an undead eyeball encased in a gem?
Publishing papers seem natural to many, while I find it really hard to think novel stuff to pursue till publication. How to cope up with this?
How do ballistic trajectories work in a rotating cylinder world?
Good sources on developing mathematical models
Why AI became applicable only after Nvidia's chips were available?
Why does Trump want a citizenship question on the census?
Is there a formal/better word than "skyrocket" for the given context?
What exactly is a "murder hobo"?
How do I explain that I don't want to maintain old projects?
Who goes first? Person disembarking bus or the bicycle?
Writing an ace/aro character?
Why is CSS Grid row height different in Safari?
Chrome / Safari not filling 100% height of flex parentWhy is percentage height not working on my div?CSS 100% height with padding/marginMake a DIV fill an entire table cellHow can I transition height: 0; to height: auto; using CSS?How to make flexbox children 100% height of their parent?Twitter bootstrap 3 two columns full heightItems that span all columns/rows using CSS grid layoutCSS Grid Row Height Safari BugCSS Grid and Absolute Positioning on SafariCSS Grid does not work in Firefox and SafariCSS grid items overflow grid container when using “align-content: space-between” and a sticky header
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have used CSS Grid to lay out a difficult grid layout where grid items have varying heights and widths. 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.
This has all worked perfectly in Chrome and Firefox and even in IE with the help of the -ms- prefix.
In Safari, it's a different story:
However, in Safari the grid row does not seem to be calculated the same way — the height of the rows is much, much shorter in Safari than any other browser, which ruins the layout. Why is this?
Removing position absolute from the grid element doesn't change the row height. But it seems that putting height: 0 on the grid wrapper does something that makes the row height behave the same in Safari as it does in Chrome and Firefox. What's the reason behind this?
Code:
Codepen: https://codepen.io/katrina-isabelle/pen/rRqvXq
.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>css safari css-grid
add a comment |
I have used CSS Grid to lay out a difficult grid layout where grid items have varying heights and widths. 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.
This has all worked perfectly in Chrome and Firefox and even in IE with the help of the -ms- prefix.
In Safari, it's a different story:
However, in Safari the grid row does not seem to be calculated the same way — the height of the rows is much, much shorter in Safari than any other browser, which ruins the layout. Why is this?
Removing position absolute from the grid element doesn't change the row height. But it seems that putting height: 0 on the grid wrapper does something that makes the row height behave the same in Safari as it does in Chrome and Firefox. What's the reason behind this?
Code:
Codepen: https://codepen.io/katrina-isabelle/pen/rRqvXq
.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>css safari css-grid
If I remember well, Safari doesn't like the unit%you have used for.grid. In general I would use for grid layouts within safaridisplay: flex. But that's just my personal preference.
– Demian
Mar 25 at 23:35
@Demian Just wanted to note, if you inspect the elements you'll see that the.gridelement does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?
– kisabelle
Mar 26 at 16:51
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
@Demian Would love to see an example. I just trieddisplay: flexon.gridanddisplay: inline-flexon.grid-itemsand it broke the layout
– kisabelle
Mar 26 at 18:48
add a comment |
I have used CSS Grid to lay out a difficult grid layout where grid items have varying heights and widths. 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.
This has all worked perfectly in Chrome and Firefox and even in IE with the help of the -ms- prefix.
In Safari, it's a different story:
However, in Safari the grid row does not seem to be calculated the same way — the height of the rows is much, much shorter in Safari than any other browser, which ruins the layout. Why is this?
Removing position absolute from the grid element doesn't change the row height. But it seems that putting height: 0 on the grid wrapper does something that makes the row height behave the same in Safari as it does in Chrome and Firefox. What's the reason behind this?
Code:
Codepen: https://codepen.io/katrina-isabelle/pen/rRqvXq
.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>css safari css-grid
I have used CSS Grid to lay out a difficult grid layout where grid items have varying heights and widths. 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.
This has all worked perfectly in Chrome and Firefox and even in IE with the help of the -ms- prefix.
In Safari, it's a different story:
However, in Safari the grid row does not seem to be calculated the same way — the height of the rows is much, much shorter in Safari than any other browser, which ruins the layout. Why is this?
Removing position absolute from the grid element doesn't change the row height. But it seems that putting height: 0 on the grid wrapper does something that makes the row height behave the same in Safari as it does in Chrome and Firefox. What's the reason behind this?
Code:
Codepen: https://codepen.io/katrina-isabelle/pen/rRqvXq
.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>.grid-wrapper
position: relative;
padding-bottom: 60%;
.grid
display: grid;
grid-gap: 2px;
grid-template-columns: 29% 21% 21% 29%;
grid-auto-rows: 1fr;
position: absolute;
width: 100%;
height: 100%;
.grid-item
width: 100%;
color: #ccc;
background: #ccc;
.grid-item--1
grid-row: span 2;
.grid-item--2
grid-row: span 3;
.grid-item--3
grid-row: span 2;
.grid-item--4
grid-row: span 3;
.grid-item--5
grid-row: span 2;
.grid-item--6
grid-row: span 3;
.grid-item--7
grid-row: span 2;
.grid-item--8
grid-row: span 2;
.grid-item--9
grid-row: span 1;
<div class="grid-wrapper">
<div class="grid">
<div class="grid-item grid-item--1">
Grid item
</div>
<div class="grid-item grid-item--2">
Grid item
</div>
<div class="grid-item grid-item--3">
Grid item
</div>
<div class="grid-item grid-item--4">
Grid item
</div>
<div class="grid-item grid-item--5">
Grid item
</div>
<div class="grid-item grid-item--6">
Grid item
</div>
<div class="grid-item grid-item--7">
Grid item
</div>
<div class="grid-item grid-item--8">
Grid item
</div>
<div class="grid-item grid-item--9">
Grid item
</div>
</div>
</div>css safari css-grid
css safari css-grid
edited Mar 26 at 17:14
kisabelle
asked Mar 25 at 22:34
kisabellekisabelle
3011 gold badge2 silver badges9 bronze badges
3011 gold badge2 silver badges9 bronze badges
If I remember well, Safari doesn't like the unit%you have used for.grid. In general I would use for grid layouts within safaridisplay: flex. But that's just my personal preference.
– Demian
Mar 25 at 23:35
@Demian Just wanted to note, if you inspect the elements you'll see that the.gridelement does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?
– kisabelle
Mar 26 at 16:51
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
@Demian Would love to see an example. I just trieddisplay: flexon.gridanddisplay: inline-flexon.grid-itemsand it broke the layout
– kisabelle
Mar 26 at 18:48
add a comment |
If I remember well, Safari doesn't like the unit%you have used for.grid. In general I would use for grid layouts within safaridisplay: flex. But that's just my personal preference.
– Demian
Mar 25 at 23:35
@Demian Just wanted to note, if you inspect the elements you'll see that the.gridelement does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?
– kisabelle
Mar 26 at 16:51
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
@Demian Would love to see an example. I just trieddisplay: flexon.gridanddisplay: inline-flexon.grid-itemsand it broke the layout
– kisabelle
Mar 26 at 18:48
If I remember well, Safari doesn't like the unit
% you have used for .grid. In general I would use for grid layouts within safari display: flex. But that's just my personal preference.– Demian
Mar 25 at 23:35
If I remember well, Safari doesn't like the unit
% you have used for .grid. In general I would use for grid layouts within safari display: flex. But that's just my personal preference.– Demian
Mar 25 at 23:35
@Demian Just wanted to note, if you inspect the elements you'll see that the
.grid element does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?– kisabelle
Mar 26 at 16:51
@Demian Just wanted to note, if you inspect the elements you'll see that the
.grid element does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?– kisabelle
Mar 26 at 16:51
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
@Demian Would love to see an example. I just tried
display: flex on .grid and display: inline-flex on .grid-items and it broke the layout– kisabelle
Mar 26 at 18:48
@Demian Would love to see an example. I just tried
display: flex on .grid and display: inline-flex on .grid-items and it broke the layout– kisabelle
Mar 26 at 18:48
add a comment |
2 Answers
2
active
oldest
votes
(Posting as an answer in order to include pictures.)
I'm getting these results with Safari and Chrome (Vivaldi), after following your suggested fix with setting height: 0. As you say, this expands the height of the divs from a nearly collapsed state in Safari.
I'm wondering: Is it the solution on the left you are aiming for, or should it be like on the right?
If the alternative on the left is your goal you could get the same results with setting grid-auto-rows: auto on .grid.
I guess in both cases (the height: 0 and grid-auto-rows: auto) you are somehow effectively escaping calculation of height as fractions of the .grid-wrappers height.
I can't say why Safari does this in such a different way, but - pragmatically - I would personally consider using grid areas instead of spans to place the elements - at least if the layout is fairly given.

The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
add a comment |
Instead of height: 100% on the grid container (.grid), use height: 100vh.
Or, if you really want to use percentages, then make sure the parent has a defined height. Some browsers still adhere to an old rule about percentage heights, namely:
An element with a percentage height must have a parent with a defined height as a reference point or the percentage height will be ignored.
More details here:
- Working with the CSS
heightproperty and percentage values - Chrome / Safari not filling 100% height of flex parent
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so100vhis not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use theheight: 0trick than have to write all those media queries
– kisabelle
Mar 26 at 16:47
height: 100vhis a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.
– Michael_B
Mar 26 at 17:00
So the parent (.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the.grid?
– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347359%2fwhy-is-css-grid-row-height-different-in-safari%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
(Posting as an answer in order to include pictures.)
I'm getting these results with Safari and Chrome (Vivaldi), after following your suggested fix with setting height: 0. As you say, this expands the height of the divs from a nearly collapsed state in Safari.
I'm wondering: Is it the solution on the left you are aiming for, or should it be like on the right?
If the alternative on the left is your goal you could get the same results with setting grid-auto-rows: auto on .grid.
I guess in both cases (the height: 0 and grid-auto-rows: auto) you are somehow effectively escaping calculation of height as fractions of the .grid-wrappers height.
I can't say why Safari does this in such a different way, but - pragmatically - I would personally consider using grid areas instead of spans to place the elements - at least if the layout is fairly given.

The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
add a comment |
(Posting as an answer in order to include pictures.)
I'm getting these results with Safari and Chrome (Vivaldi), after following your suggested fix with setting height: 0. As you say, this expands the height of the divs from a nearly collapsed state in Safari.
I'm wondering: Is it the solution on the left you are aiming for, or should it be like on the right?
If the alternative on the left is your goal you could get the same results with setting grid-auto-rows: auto on .grid.
I guess in both cases (the height: 0 and grid-auto-rows: auto) you are somehow effectively escaping calculation of height as fractions of the .grid-wrappers height.
I can't say why Safari does this in such a different way, but - pragmatically - I would personally consider using grid areas instead of spans to place the elements - at least if the layout is fairly given.

The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
add a comment |
(Posting as an answer in order to include pictures.)
I'm getting these results with Safari and Chrome (Vivaldi), after following your suggested fix with setting height: 0. As you say, this expands the height of the divs from a nearly collapsed state in Safari.
I'm wondering: Is it the solution on the left you are aiming for, or should it be like on the right?
If the alternative on the left is your goal you could get the same results with setting grid-auto-rows: auto on .grid.
I guess in both cases (the height: 0 and grid-auto-rows: auto) you are somehow effectively escaping calculation of height as fractions of the .grid-wrappers height.
I can't say why Safari does this in such a different way, but - pragmatically - I would personally consider using grid areas instead of spans to place the elements - at least if the layout is fairly given.

(Posting as an answer in order to include pictures.)
I'm getting these results with Safari and Chrome (Vivaldi), after following your suggested fix with setting height: 0. As you say, this expands the height of the divs from a nearly collapsed state in Safari.
I'm wondering: Is it the solution on the left you are aiming for, or should it be like on the right?
If the alternative on the left is your goal you could get the same results with setting grid-auto-rows: auto on .grid.
I guess in both cases (the height: 0 and grid-auto-rows: auto) you are somehow effectively escaping calculation of height as fractions of the .grid-wrappers height.
I can't say why Safari does this in such a different way, but - pragmatically - I would personally consider using grid areas instead of spans to place the elements - at least if the layout is fairly given.

answered Mar 26 at 0:21
jensmtgjensmtg
5185 silver badges19 bronze badges
5185 silver badges19 bronze badges
The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
add a comment |
The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
The one on the right is the desired layout. In the one on the left, it looks like you copied my SCSS but didn't enable the SCSS preprocessor
– kisabelle
Mar 26 at 16:41
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
Could you provide an example using grid areas instead of spans? I'm new to grid and unfamiliar with that concept
– kisabelle
Mar 26 at 16:49
add a comment |
Instead of height: 100% on the grid container (.grid), use height: 100vh.
Or, if you really want to use percentages, then make sure the parent has a defined height. Some browsers still adhere to an old rule about percentage heights, namely:
An element with a percentage height must have a parent with a defined height as a reference point or the percentage height will be ignored.
More details here:
- Working with the CSS
heightproperty and percentage values - Chrome / Safari not filling 100% height of flex parent
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so100vhis not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use theheight: 0trick than have to write all those media queries
– kisabelle
Mar 26 at 16:47
height: 100vhis a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.
– Michael_B
Mar 26 at 17:00
So the parent (.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the.grid?
– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
add a comment |
Instead of height: 100% on the grid container (.grid), use height: 100vh.
Or, if you really want to use percentages, then make sure the parent has a defined height. Some browsers still adhere to an old rule about percentage heights, namely:
An element with a percentage height must have a parent with a defined height as a reference point or the percentage height will be ignored.
More details here:
- Working with the CSS
heightproperty and percentage values - Chrome / Safari not filling 100% height of flex parent
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so100vhis not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use theheight: 0trick than have to write all those media queries
– kisabelle
Mar 26 at 16:47
height: 100vhis a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.
– Michael_B
Mar 26 at 17:00
So the parent (.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the.grid?
– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
add a comment |
Instead of height: 100% on the grid container (.grid), use height: 100vh.
Or, if you really want to use percentages, then make sure the parent has a defined height. Some browsers still adhere to an old rule about percentage heights, namely:
An element with a percentage height must have a parent with a defined height as a reference point or the percentage height will be ignored.
More details here:
- Working with the CSS
heightproperty and percentage values - Chrome / Safari not filling 100% height of flex parent
Instead of height: 100% on the grid container (.grid), use height: 100vh.
Or, if you really want to use percentages, then make sure the parent has a defined height. Some browsers still adhere to an old rule about percentage heights, namely:
An element with a percentage height must have a parent with a defined height as a reference point or the percentage height will be ignored.
More details here:
- Working with the CSS
heightproperty and percentage values - Chrome / Safari not filling 100% height of flex parent
answered Mar 26 at 2:01
Michael_BMichael_B
169k51 gold badges278 silver badges386 bronze badges
169k51 gold badges278 silver badges386 bronze badges
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so100vhis not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use theheight: 0trick than have to write all those media queries
– kisabelle
Mar 26 at 16:47
height: 100vhis a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.
– Michael_B
Mar 26 at 17:00
So the parent (.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the.grid?
– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
add a comment |
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so100vhis not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use theheight: 0trick than have to write all those media queries
– kisabelle
Mar 26 at 16:47
height: 100vhis a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.
– Michael_B
Mar 26 at 17:00
So the parent (.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the.grid?
– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so
100vh is not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use the height: 0 trick than have to write all those media queries– kisabelle
Mar 26 at 16:47
I mentioned in the second paragraph that I'm trying to maintain the aspect ratio of the grid, so
100vh is not appropriate for my use case. Defining the height in pixels means that I would have to create many media queries to maintain the aspect ratio, which is why I used the percentage padding trick. I would rather use the height: 0 trick than have to write all those media queries– kisabelle
Mar 26 at 16:47
height: 100vh is a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.– Michael_B
Mar 26 at 17:00
height: 100vh is a percentage, but it's relative to the viewport. The other option I presented is also a percentage, but implemented in accordance with spec rules.– Michael_B
Mar 26 at 17:00
So the parent (
.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the .grid?– kisabelle
Mar 26 at 17:11
So the parent (
.grid-wrapper) doesn't have a defined height because the height is being set by the padding – this is how the aspect ratio is maintained. Any ideas on how I can maintain the aspect ratio if I'm defining the height of the parent or the .grid?– kisabelle
Mar 26 at 17:11
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
Also, to clarify, the grid is displayed at a width of 100% so that's why the aspect ratio would not be maintained if the height is relative to the viewport height.
– kisabelle
Mar 26 at 17:13
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347359%2fwhy-is-css-grid-row-height-different-in-safari%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If I remember well, Safari doesn't like the unit
%you have used for.grid. In general I would use for grid layouts within safaridisplay: flex. But that's just my personal preference.– Demian
Mar 25 at 23:35
@Demian Just wanted to note, if you inspect the elements you'll see that the
.gridelement does expand to fill the height of it's parent, it's the rows inside the grid that are not expanding. How would you recreate this layout in flex?– kisabelle
Mar 26 at 16:51
With parent flex and children inline-flex.
– Demian
Mar 26 at 18:32
@Demian Would love to see an example. I just tried
display: flexon.gridanddisplay: inline-flexon.grid-itemsand it broke the layout– kisabelle
Mar 26 at 18:48