Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CSS position: sticky in mobile browsers?

Added some position: sticky property to my webpage. On Desktop browser work fine but sucks in mobiles.

like image 448
Ulukbek Abylbekov Avatar asked Jul 22 '17 01:07

Ulukbek Abylbekov


People also ask

How do I apply position sticky in CSS?

CSS Demo: position To see the effect of sticky positioning, select the position: sticky option and scroll this container. The element will scroll along with its container, until it is at the top of the container (or reaches the offset specified in top ), and will then stop scrolling, so it stays visible.

Why is position sticky not working CSS?

That can happen for many reasons: Position sticky will most probably not work if overflow is set to hidden, scroll, or auto on any of the parents of the element. Position sticky may not work correctly if any parent element has a set height. Many browsers still do not support sticky positioning.

Does position sticky work in Chrome?

It is available on Chrome (yay), Firefox and Safari. Here are more details about position:sticky : Specification.

Does Safari support position sticky?

Browsers Support Position Sticky is supported by all major modern browsers, except for old IE. For Safari browsers you will need to add the -webkit prefix.


1 Answers

sticky property for Chrome and Safari for iOS needs to be set with -webkit vendor first:

.element {
  position: -webkit-sticky;
  position: sticky;
}

You can check about browser compatibility in canIUse

like image 101
Cezar Augusto Avatar answered Sep 19 '22 15:09

Cezar Augusto