A parent element must have `position: relative` for child elements with `position: absolute` to move correctly. Use `top: 50%; transform: translateY(-50%)` to center an element vertically. Avoid using the same CSS class for different styles on the same page.
By Pawan Nayar · from the LLOS AI Learning record
A parent element must have `position: relative` for child elements with `position: absolute` to move correctly.
Use `top: 50%; transform: translateY(-50%)` to center an element vertically. Avoid using the same CSS class for different styles on the same page.
A developer can set the parent element's CSS `position` to `relative`. This allows child elements with `position: absolute` to move within the parent. The child element's position will then be calculated from the parent's edges. This method helps keep related elements grouped visually.
A developer creates a `div` element to hold an image. The developer wants to place a small icon exactly in the corner of the image. The developer sets the `div` to `position: relative`. The developer sets the icon to `position: absolute` and uses `top` and `left` properties. The icon then stays in the image's corner, even if the image moves.
Resolved from this lesson's own record — real definitions, not invented for this page.
More from the same record, pulled by shared topic — not written new for this page.
A button should only be as wide as its text and the space around the text. This is called content-sized.
The main container, `.flip-card`, has a fixed height and `perspective`. This creates a 3D viewing effect.
A developer should give the map wrapper `position: relative` and `z-index: 1`. This creates a stacking context.
A developer tried to fix a display issue. The developer wrapped two elements, `#status` and `#milestoneFooter`, in a new container called `.status-slot`.
A parent element must have `position: relative` for child elements with `position: absolute` to move correctly. Use `top: 50%; transform: translateY(-50%)` to center an element vertically. Avoid using the same CSS class for different styles on the same page.