Antoine BERNIER
Sep 12, 2018 Β· 1 min read
.aspectRatioSizer:before {
content:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7 2"></svg>');
}
<div class="aspectRatioSizer">
<div>
Content goes here
</div>
</div>

No more ratio value into HTML, but CSS πŸ˜‰

@mixin aspectRatioSizer($w:1, $h:1) {
&:before {
content:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{$w} #{$h}"></svg>');
}
display:grid;
&:before, >* {grid-area: 1 / 1 / 2 / 2;}
}
#myel {
@include aspectRatioSizer(7,2);
}

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium β€” and support writers while you’re at it. Just $5/month. Upgrade