How can CSS be used to implement a sticky header that remains at the top of the viewport during scrolling?
- Position: sticky;
- Position: fixed;
- Position: relative;
- Position: absolute;
The correct option is Position: sticky;. This CSS property is used to create a sticky element that remains fixed at the top of the viewport during scrolling. It is often used for headers or navigation bars. Position: fixed; would also keep the element fixed but without regard to its parent container. Position: relative; and Position: absolute; have different behaviors in relation to the normal flow of the document.
Loading...
Related Quiz
- A child element does not inherit the __________ property from its parent by default in CSS.
- In a grid layout, how would you make an element occupy the space of two columns starting from the second column?
- To prevent floated elements from affecting the layout of the following elements, the ________ property is often used.
- The pseudo-class :nth-of-type(2) in CSS targets the ________ of its type.
- What does specificity determine in CSS?