I have the following HTML:
<div class="grid">
<div>
<h1>
Element with a really, really, really loooooooooong title
</h1>
</div>
<div>
Element 2
</div>
</div>
And this is the CSS that I apply to it:
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 1rem;
}
.grid > div h1 {
white-space: nowrap;
}
It seems that, however, the two columns do not have equal widths (1fr
) as they should be (repeat(2, 1fr)
) because of the h1
in the first element having white-space: nowrap
.
On the other hand, if you change the grid-template-columns
property to:
grid-template-columns: repeat(2, calc(50% - 1rem));
the grid then is visualized correctly.
Here's a fiddle for those of you who want to reproduce this by themselves.
My question is why is fr
being ignored because of the nowrap
property of a child element? Is this expected behavior or is it an issue with CSS grid itself?