| Desktop | Mobile |
|---|---|
![]() |
![]() |
- Using Negative Margins for Vertical Positioning
I encountered this technique while trying to vertically overlap the FAQ box on top of the header background. My initial approach was to useposition: absoluteon the FAQ box. However, since it was the only content inside<main>, this caused the main section to collapse—losing its background color and bottom spacing.
To solve this, I needed the FAQ box to remain part of the normal document flow so that<main>could retain its layout and styling, while still visually overlapping the header. Applying a negative top margin to the FAQ box achieved exactly that: it preserved the flow and allowed the visual overlap.
In other scenarios—where the parent container doesn’t rely on the child’s presence for layout—position: absolutecan still be a valid and clean solution.
- Github - @AminForouzan
- Frontend Mentor - @AminForouzan

