Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not used position:fixed for a "sticky" footer?

I've seen Ryan Fait's method for sticky footer as well as one here and here.

Why are these people making templates for sticky footers when #footer{position:fixed; bottom:0;} will suffice?

EDIT:

I will add that using position: fixed; for a footer does break margin: auto; centering in (at least) some browsers, thus creating the need for a wrapper tag. Part of my problem with the above mentioned methods is the extra tags which are confusing, syntactically incorrect (for the "HTML purists") and it eats bandwidth. However, a single wrapper around the footer is still, in my opinion, better than a whole jumbled page template to have to start with. And, "my" way is still more straightforward and eats less bandwidth.

like image 575
Moshe Avatar asked Feb 15 '10 22:02

Moshe


People also ask

Should I use fixed or sticky?

It depends, when you want that element simply doesnt move in your website then use fixed . But be careful with position: fixed , it can potentially cover other element. When you want that element scrolling into view and then stop at certain point, use sticky .

What position should a footer be?

The footer should be positioned at the bottom of the page when the content is empty. The footer should be 'pushed' down when the content exceeds the height of the page.

What is the difference between position fixed and sticky?

1. Element with position: fixed property is fixed to the viewport and doesn't move irrespective of scrolling. Element with position: sticky property can scroll to an offset value provided by the user.


1 Answers

The difference between using position: fixed and Ryan Fait's method1 is pretty fundamental.

When using position: fixed, the footer is always visible, and that's not what a sticky footer is trying to do.
The meaning of a sticky footer is to stay sticked to the bottom, except if the content is longer than the viewport height. In that case, the sticky footer will act like a normal footer, appearing just below the page content.

Here you can see the effect of a sticky footer. In the Result window, you see that the footer stays at the bottom of the page. Click on the 'Add content' button to add content, and then you will see that the footer shifts down to stay below the content.


1. This is a snapshot of 10 January 2013 from the Wayback Machine, as Ryan's website itself does not contain the original post any longer.

like image 86
MC Emperor Avatar answered Sep 30 '22 19:09

MC Emperor