80%
DefinitionCSS styles HTML.
p: (0, 0, 1)
.card p: (0, 1, 1)
#main .card p: (1, 1, 1)
style="…" inline: beats all selectors
a = IDs, b = classes / attributes / pseudo-classes, c = elements / pseudo-elements.
Some properties inherit (color, font); most don't (margin, border).
FlowFrom the inside outcontent→padding→border→margin
content-box (default): width = content only, so padding and border add to it.Vertical margins between blocks collapse (the larger one wins); flex and grid items don't collapse.
display: none removes the element; visibility: hidden keeps its space; opacity: 0 keeps space and stays clickable.static: — · yes (default)
relative: its own normal position · yes (space kept)
absolute: nearest positioned ancestor · no
fixed: the viewport · no
Tipz-index only works on positioned (or flex/grid) elements, and only competes inside the same stacking context (created by position + z-index, opacity…
flex-direction: row (default) or column — sets the main axis
justify-content: alignment along the main axis
align-items: alignment along the cross axis
flex-wrap: allow items to wrap to new lines
Use Flexbox for a row or column of items; use Grid for rows *and* columns (page layouts, galleries).
fr = a fraction of the free space; minmax(min, max) sets size limits.grid-template-areas names regions ("header header" / "sidebar main").Mobile-first: base styles for small screens, then
@media (min-width: 768px) { … } for bigger ones.rem = relative to the root font size (good for spacing and type); em = relative to the parent font size.% relative to the parent; vw/vh relative to the viewport; dvh handles mobile browser bars.clamp(1rem, 2.5vw, 2rem) = fluid size with a min and max.Common mistakeFixed pixel widths on containers cause horizontal scrolling on phones.
Animate
transform and opacity — they skip layout and paint (GPU-friendly).Animating
width, top or margin triggers reflow on every frame.Respect
@media (prefers-reduced-motion: reduce).Pseudo-classes target state (
:hover, :focus-visible, :nth-child); pseudo-elements add parts (::before, ::after).ReviseSpecificity (IDs > classes > elements), border-box, Flexbox for 1-D and Grid for 2-D, mobile-first with rem and clamp, animate transform/opacity.