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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *