position: absoluteposition: absolute inside a container without any positioning?position set.An element with position: absolute is taken out of the normal flow and positioned relative to the nearest ancestor that has a positioning other than static. If no such ancestor exists, it positions relative to the initial containing block (usually the viewport).
.container { position: relative; width: 200px; height: 200px; background: blue; }.box { position: absolute; top: 20px; left: 30px; width: 50px; height: 50px; background: red; }Because the container has position: relative, the absolutely positioned red box uses it as the reference point. So top: 20px and left: 30px place the red box inside the blue container at those distances.
position: absolute<div class='parent'><div class='child1'>A</div><div class='child2'>B</div></div>.parent { position: relative; width: 150px; height: 150px; background: lightgray; }.child1 { position: absolute; top: 20px; left: 20px; width: 100px; height: 100px; background: red; z-index: 1; }.child2 { position: absolute; top: 50px; left: 50px; width: 100px; height: 100px; background: blue; }Which box will appear on top visually?
The red box has z-index: 1 which is higher than the default z-index: auto of the blue box. This means the red box will be drawn on top of the blue box where they overlap.
position: absolute applied?Only option A uses an attribute selector to find elements with inline styles containing position: absolute. The others are pseudo-class selectors that do not select by style attribute.
position: absolute for UI elements like modals or tooltips, what is the most important accessibility practice?Absolutely positioned UI elements like modals must be accessible. This means managing keyboard focus so users can tab into and out of them, and using ARIA roles (like role='dialog') so screen readers announce them properly.