position: sticky not working in firefox
Asked Answered
F

13

18

position:sticky is said to be working in firefox but I'm not seeing my sidebar stick.

My html looks like this:

<div class="wrap">

    <div class="sticky">side </div>    
    <div class="content">content <div>
<div>

My css:

.content{
    height: 2000px;
    overflow: hidden;
}

.sticky{
    position: sticky;
    width: 200px;
    float: left;
}

As I scroll down the sidebar scrolls with the content. It doesn't stick. Anyone know what could be the issue?

Foskett answered 17/12, 2014 at 8:59 Comment(4)
What FireFox version?Fieldwork
I have the latest versionFoskett
As of Feb 2018 position: sticky for th still doesn't work in FF 58.0 (64-bit). Three years behind!Sunlight
Yep it still doesn't work on thead and tr elements in ff chrome opera and maybe more browsersGlengarry
I
10

It sticks if you specify a top value:

.sticky{
   position: -webkit-sticky; /* for safari */
   position: sticky;
   width: 200px;
   float: left;
   top: 10px;
}

fiddle

Impeccable answered 17/12, 2014 at 9:8 Comment(2)
This doesn't work when you put the sticky thing below something else: jsfiddle.net/3qoe0wd0/44 I'm using Firefox 50.1.0Schoolgirl
@ChrisSmith The html markup is broken in your fiddle. That is likely an issue. The div tag isn't closed on the content class.Beeson
B
19

I have the same issue in 2020 - this post pops up first in google but none of the answers helped me.

The actual problem was that sticky doesn't play well with the parent element being display: flex.

References:
- position: sticky, works in Chrome but not in Firefox
- https://bugzilla.mozilla.org/show_bug.cgi?id=1488080

Bedspring answered 26/3, 2020 at 23:42 Comment(4)
I'm so bummed that this bug hasn't been fixed yet. I guess it's low priority but it breaks my app's layout in Firefox.Jackstay
same issue in a display:grid element. Works like a dream on Chrome, scrolls right through my footer in firefox and then doesnt stick on the way up :(Hutt
@Hutt Using display:block for sticky element helped me solve the same problem.Hoopoe
It also doesn't work if the parent element has overflow hiddenHawkweed
I
10

It sticks if you specify a top value:

.sticky{
   position: -webkit-sticky; /* for safari */
   position: sticky;
   width: 200px;
   float: left;
   top: 10px;
}

fiddle

Impeccable answered 17/12, 2014 at 9:8 Comment(2)
This doesn't work when you put the sticky thing below something else: jsfiddle.net/3qoe0wd0/44 I'm using Firefox 50.1.0Schoolgirl
@ChrisSmith The html markup is broken in your fiddle. That is likely an issue. The div tag isn't closed on the content class.Beeson
L
3

Position sticky also don't work if the parent element is set to overflow: hidden because it can't calculate the height correctly.

Lothaire answered 11/6, 2019 at 11:9 Comment(1)
It will not work with overflow-x: hidden as well. So, any overflow (e.g. overflow, overflow-y, overflow-x) will bug out sticky.Lsd
L
2

I was able to fix it by using 'display: table-cell'.

My problem concerned a thead that didn't want to stick anymore on Firefox as soon as I fixed the same problem in Chrome by using display: block or inline-block.

Leverhulme answered 20/7, 2020 at 15:6 Comment(1)
setting display: table-cell and also float: unset (because I had another rule that tried to float the element) fixed it for me (inside a table inside a scroll-container inside a flexbox with overflow hidden) ...now I just need to go back to Chrome and make sure it still works there too :/Dasher
K
1

position: sticky does not work on table elements such as tr as well as some others.

A workaround is to wrap whatever you want sticky inside a span element.

    <style>.sticky span {position: -webkit-sticky; position: sticky; top: 0;}</style> 
    <td class='sticky' valign='top' width='200'>
    <span>
        (table contents)
    </span>
    </td>

Related answers and solutions

Kilogrammeter answered 14/1, 2019 at 5:58 Comment(0)
L
0

I had same issue, even though I set a top value, the sticky element would not stick. The solution was to set a value also for height...

Laskowski answered 22/4, 2019 at 2:3 Comment(1)
Not a solution in many scenariosRule
U
0

To anyone still having this trouble:

Firefox uses the parent display as a rendering condition

So try making the child display: inline and parent display: inline

Remember that you still need to check the parent position and size for all browsers. Sticky is great but it is very case-specific use.

Upheave answered 1/12, 2020 at 17:28 Comment(1)
Not a solution if you need the parent to be flexRule
S
0

I found the alt way with very simple but works.

position:fixed;
width:100%;
top:0;
z-index:1; /*depends on your elements*/

Work on every browsers, no bulls. If your topnav has a lot of elements, the sticky wil not working, I beleive it's because of some overflow:hidden;

Spann answered 19/5, 2021 at 6:38 Comment(0)
A
0

In my case, the sticky element was taking a display: table; property, which when I changed to display: block;, the sticky was fixed in Firefox. So, have a look at the display property before considering other fixes.

Arrogant answered 22/9, 2021 at 18:39 Comment(0)
R
0

Just stumbled on this so it seems to still be an issue in 2022. I'll leave here what I had that allowed me to clearly replicate the OP and what I added to mitigate it.

div {
  position: sticky;
- display: inline;
+ display: block;
+ height: 100px;
  z-index: 2;
  top: 0;
}
Roybn answered 3/11, 2022 at 23:37 Comment(1)
Setting a height is not an option in many scenariosRule
B
0

Hey this could be a shot in the dark, but i just fixed this bug on my code, turns out i was setting a height of 100vh to my body element, my body element in this case is a section with id=body.

in the css file i put a height of 100vh for #body element, but turns out the sticky position type did not like that and only worked once i removed it.

Boffin answered 19/11, 2023 at 0:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Monadism
B
-1
.sticky-top {
    position: -webkit-sticky;
    position: sticky;
    z-index: 1020;
    top: 86px;
    height: min-content;
}

Adding height: min-content; fixed my issue on firefox

Blackheart answered 15/4, 2020 at 8:33 Comment(0)
B
-1

I had the same issue. Try the following on the parent component:

transform: translate3d(0, 0, 0); 
overflow: inherit;
Butta answered 10/10, 2023 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.