Performance: Position absolute
Position absolute affects layout stability and paint performance by removing elements from normal flow and creating new stacking contexts.
Jump into concepts and practice - no test required
div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(50%, 50%);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using many absolute elements with frequent position changes | High (many nodes) | Multiple reflows per change | High paint cost due to overlapping | [X] Bad |
| Using few absolute elements with stable positions | Low | Single reflow on initial layout | Low paint cost | [OK] Good |
position: absolute; do to an element in CSS?position: absolute; allows exact placement with top and left.top: 20px; and left: 30px; moves the element 20px down and 30px right from its positioned ancestor.<div class='container'>
<div class='box'>Red Box</div>
</div>
.container {
position: relative;
width: 200px;
height: 200px;
background: lightgray;
}
.box {
position: absolute;
top: 50px;
right: 20px;
width: 100px;
height: 50px;
background: red;
color: white;
}position: relative;, so it becomes the reference for absolute children..child {
position: absolute;
top: 10px;
}
.parent {
width: 300px;
height: 300px;
background: blue;
}<div class='parent'> <div class='child'>Hello</div> </div>
position: relative;. Which CSS for the tooltip ensures it appears above the button using absolute positioning?.tooltip {
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%) translateY(-10px);
background: black;
color: white;
padding: 5px;
border-radius: 3px;
}bottom: 100% places the tooltip exactly at the top edge of the button.translateX(-50%) centers horizontally, and translateY(-10px) moves it 10px further up.