Problem with 'position sticky;'
I wanted the footer to be in bottom whenever the page is scrolled, but
position: fixed;
was a little problematic for me, so I used position: sticky;
, it works as expected but in some cases, it was not in bottom (like in the img). Help?30 Replies
Check the margin/padding on the body.
*
has 0 margin and 0 paddingCan you upload the code to codepen?
just the footer code
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Is the HTML and Body using 100% of the width?
We can keep guessing, or you can upload the code to codepen for us to take a look? Please see https://discord.com/channels/436251713830125568/1022288836715356180/1022288836715356180
I'm just saying because sticky elements have issues due to the width of HTML/Body.
It could be a nested element in the last element on the page that has a large enough padding or margin that causes this.
yes
But again, we're just guessing but if we had the code... 🤔
footer's parent is body
my structure
Just post a codepen.
umm ookie
@myntsu @joao6246 here https://codepen.io/GiteenShiro/pen/QWxQJBd
But in the example it works just fine?
It seems only when the viewport height is not big enough. You can probably fix by setting a min height on the body of 100vh and then going back to using position fixed on the footer
fixed or sticky?
Position fixed.
ok
but the content is going inside the footer
u sure?
If that's the effect that you want, then increase the height of the footer.
Yes,
nope
The problem with sticky is that the document will remember the position it should fit and make room for the element. If the footer was never high enough it won't cover that last gap
i want the content to be shown above the footer, not the content inside the footer
can i use max-height and fix it?
Yes just increase the height of the footer a bit until it covers the gap
but in larger devices the same problems occurs right
Mmh I'm not sure why is doing that right now, but using
top:100%
instead of bottom: 0
on the footer might work as expectedUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
No need for messing with positions, just have the body be full height and flex, with the main element taking up all the free space.
Aslo, never do this. Only change margin/padding purposefully. Generally nuking leads to "why isn't this working?" as seen here:
https://discord.com/channels/436251713830125568/1044707398750842890
Granted that example isn't
* {margin: 0;}
but the outcome is the same, they removed the margin because…no specific reason and can't figure out why there's no margin on their elements. The browser defaults are pretty good, much better than any dev I've seen who nukes margin/padding like this. You'll miss something and you'll run into spacing problems. Don't change the default without specific reasons.ummm im not much better in css
maybe i should learn it 😓