Sticky Position

The last position we will look at is the sticky position (sticky) (position). 

An element with sticky position is not ignored by other elements (similar to relative position), but it always stays on the screen (similar to fixed position). This means that it behaves like an element with relative position until it is about to disappear from the page, at which point it starts behaving like an element with fixed position. 

We can offset it in the same way as relative position. This means that we move it from its static position, not from the page or a parent with a position other than static.

Instructions

Change the position of the element with id square2 (#square2) to sticky and change the top offset to 0 pixels. Leave the rest the same.

Notice that the 3rd square does not ignore the 2nd square and that when you scroll the page, the 2nd square remains stuck at the top of the page.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

9/10