Why doesn't the height change when I set only width and aspect-ratio?
The aspect-ratio property tells the browser to calculate height automatically based on width to keep the ratio. So height changes behind the scenes even if you don't set it explicitly (see step 2).
š” If width is fixed and aspect-ratio set, height adjusts automatically to keep ratio.
What happens if I set both height and aspect-ratio?
If both height and width are set, aspect-ratio is ignored because the box size is fixed. Aspect-ratio only works when one dimension is automatic.
š” Aspect-ratio controls the missing dimension, not both.
Why does the box sometimes overflow or look stretched?
If the container or parent limits size, the fixed aspect ratio box might overflow or cause scroll. Also, if width or height is set in conflicting ways, the ratio can't be kept.
š” Use aspect-ratio with flexible containers or control max sizes.