Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of position: sticky

Setting the css attribute position to sticky causes the element to positioned relative until a certain point is scrolled too at which point it becomes fixed. How can I achieve the reverse i.e the element is fixed until a certain point then becomes relative.

To expand, imagine I have a large footer, 500px in height, which is initially out of the viewport. I want a button which initially falls to the bottom of the page, but, if the footer comes into view then the button should remain above the footer.

like image 343
Connor Bishop Avatar asked Feb 02 '18 13:02

Connor Bishop


People also ask

What is sticky position in CSS?

Watch a video course CSS - The Complete Guide (incl. Flexbox, Grid & Sass) Sticky positioning has two main parts: sticky item and sticky container. Sticky item is the element specified with the position: sticky;. The element floats when the viewport matches the defined position. Sticky container is the element wrapping the sticky item.

What is the opposite of sticky?

Antonyms for sticky include dry, nonadhesive, facile, pleasant, smooth, simple, effortless, undemanding, easy and straightforward. Find more opposite words at ...

What is the difference between relative and sticky position?

And if we scroll, the rest of the children will flow according to the document, but the fixed will stay the same. Sticky position is the combination of relative and fixed. If we set a child to sticky positioning, it will look normal, like relative.

How do I make the sticky positioning work?

To make the sticky positioning work as expected, you must specify at least one of the following properties: top, right, bottom, or left. Otherwise, it will be similar to relative positioning. Let’s see some examples. Watch a video course CSS - The Complete Guide (incl. Flexbox, Grid & Sass)


Video Answer


1 Answers

To make a element sticky at the top you add this:

element{
  position:sticky;
  top:0;
}

To make the element sticky at the bottom you need to replace top:0; with bottom:0;

element{
  position:sticky;
  bottom:0;
}
like image 178
Bart Avatar answered Sep 22 '22 01:09

Bart