A super useful recap of the main ways that CSS calculates percentage for element layout, each with a brilliant slider-based demo. The tl;dr:
- The
width
andheight
elements are based on the parent's dimensions; - So are positioning attributes such as
top
andright
; - Both
margin
andpadding
attributes inherit from the parent, but only use the width value (even for things likemargin-top
); - The
transform
property uses the element's dimensions.