HTML/CSSIntermediate#css#position

What is the difference between absolute and fixed positioning in terms of containing block?

absolute positions relative to the nearest ancestor with position other than static (or the initial containing block if none exists), and scrolls with that ancestor. fixed positions relative to the viewport (or a transformed ancestor) and stays in place during page scroll.

Example
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: 100%; left: 0; }

Related Questions

1
HTML/CSSBeginner#css#flexbox

What is the CSS 'gap' property and how does it simplify spacing in flex/grid layouts?

Open
2
HTML/CSSBeginner#css#selectors

What is the difference between class selectors and ID selectors, and why avoid IDs for styling?

Open
3
HTML/CSSAdvanced#css#layout-puzzle

How do you build a CSS-only accordion or tab component?

Open