Today I Learned - Rocky Kev

TIL how to Make a Square with CSS with aspect-ratio

POSTED ON:

TAGS:

If you want to make a square without having to mess around too much with width and height, you can style your div [or span as the case may be] by setting a background color, the width you need, and then an aspect-ratio with equal figures. The first figure is for the top and bottom dimension, the second is for left and right.

.square {
background: green;
width: 25rem;
aspect-ratio: 1/1;
}

Via CSS Cheat Sheet – 10 Tricks to Improve Your Next Coding Project


Related TILs

Tagged:

TIL the alternate keyword

If 'alternate' appears along with the stylesheet keyword, the linked file is an alternative stylesheet. It won’t be applied to the document, but it will be ready for when we need it.

TIL Logical Properties

For that sweet sweet Internationalization you want to avoid directional words like 'left', 'right', 'top', and 'bottom'.

TIL Using pseudo-classes in your querySelector!

let notTuna = document.querySelectorAll('.sandwich:not(.tuna)')