Almost every question and answer I have found talks about the viewport size; this isn't really my issues.
Take this Pen... https://codepen.io/njt1982/pen/pZjZNM
I have a very basic Bootstrap 4 grid like this:
<div class="container mt-4">
<div class="row">
<div class="col border"><div class="tile"><span>A</span></div></div>
<div class="col border"><div class="tile"><span>B</span></div></div>
...
...
</div>
<div class="row">
<div class="col border"><div class="tile"><span>A</span></div></div>
<div class="col border"><div class="tile"><span>B</span></div></div>
...
...
</div>
...
...
</div>
And some CSS to make these into squares (using the padding-top: 100%
trick):
.col {
padding: 0;
}
.col:not(:last-child) {
border-right: none !important;
}
.row:not(:last-child) .col {
border-bottom: none !important;
}
.tile {
padding: 100% 0 0;
font-size: 5vw;
}
.tile span {
position: absolute;
left: 0;
top: 50%;
line-height: 0;
width: 100%;
text-align: center;
}
The problem here is that 5vw makes the font just the right size on my 2560px wide viewport, but by the time I have reached the lower breakpoint, it not longer fills the cells. I'd like to avoid tonnes of media queries to "tune" it.
Is there any CSS-only way of saying "font-size = container_height"?
font-size: 100%
seems to just set the font to the base size (not the parent size, like you'd expectheight: 100%
to do). Some goes for the likes ofem
's...- I've tried
vh
and that works fine until the viewport height changes (so same problem as vw). - I read something about vb (about the parent block), but that doesn't seem to work? I believe it is still only theoretical.
- I am aware of JS-options which could calculate the height of a parent and set it... But I feel like this is something CSS should be able to do and I'm missing a piece of a puzzle.
- Could the answer lie in transforms?! or
calc()
?
UPDATE: Possible answer using SVGs? https://stackoverflow.com/a/51333267/224707