How To Create a Sticky Element | sticky css
LearnhowtocreateastickyelementwithCSS.TryitYourself»[1]Note:ThisexampledoesnotworkinInternetExplorerorEdge15andearlierversions.StickyElementExamplediv.sticky{ position:-webkit-sticky;/*Safari*/ position:sticky; top:0;}TryitYourself»[2]Anelementwithposition:sticky;ispositionedbasedontheusersscrollposition.Astickyelementtogglesbetweenrelativeandfixed,dependingonthescrollposition.Itispositionedrelativeuntilagivenoffsetpositionismetintheviewport-thenit"sticks"inplace(likeposition:fixed).Note:In...
Learn how to create a sticky element with CSS.
Try it Yourself »[1]
Note: This example does not work in Internet Explorer or Edge 15 and earlier versions.
Sticky Element Examplediv.sticky { position: -webkit-sticky; /* Safari */ position: sticky; top: 0;}
Try it Yourself »[2]An element with position: sticky; is positioned based on the users scroll position.
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).
Note: Internet Explorer, Edge 15 and earlier versions do not support sticky positioning. Safari requires a -webkit- prefix (see example below). You must also specify at least one of top, right, bottom or left for sticky positioning to work.
To learn more about CSS positoning, read our CSS Position[3] tutorial.
Referen...