#205: Sticky Positioning: How it Works, What Can Break It, and Dumb Tricks

Programming - Mar 31, 2024

How it works

You apply position: sticky; to an element along with a top, left, right, or bottom threshold and it will “stick” in that position when the threshold is passed, as long as there is room to move within the parent container.

What can break it

  • You forgot to apply position: sticky;.
  • You forgot to apply a position threshold like top, left, bottom, or right.
  • You’re looking in an old-Safari browser and didn’t use -webkit-sticky as the value.
  • The threshold you applied doesn’t apply in that scroll direction.
  • There is no room to move in the parent container.
  • A parent element has hidden overflow (even in a direction that doesn’t matter to the scrolling).

Weird tricks

Usings transforms like scale() and rotate(), the behavior of position: sticky; can get pretty weird, like this “slide by” behavior:

Previous Next
Copyrights
We respect the property rights of others, and are always careful not to infringe on their rights, so authors and publishing houses have the right to demand that an article or book download link be removed from the site. If you find an article or book of yours and do not agree to the posting of a download link, or you have a suggestion or complaint, write to us through the Contact Us .
Read More