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
widthandheightelements are based on theΒ parent's dimensions; - So are positioning attributes such as
topandright; - Both
marginandpaddingattributes inherit from the parent, but only use the width value (even for things likemargin-top); - The
transformproperty uses the element's dimensions.