How to create sticky headers and footers with CSS

CSS offers a native way to create headers and footers that fix at the top (or at the bottom) of the screen.

Both ways, your elements have to be placed like this:

<div id=”container”>
<header>…</header>

<footer>…..


This content originally appeared on DEV Community and was authored by Juan Belieni

CSS offers a native way to create headers and footers that fix at the top (or at the bottom) of the screen.

Both ways, your elements have to be placed like this:

<div id="container">
  <header>...</header>
  ...
  <footer>...</footer>
</div>

Where the #container element is the one that users will scroll by. In other words, your header or footer will not be sticky to the screen if it has another element surrounding them.

At your CSS, you will just have to do this:

header {
  position: sticky;
  top: 0;
}

footer {
  position: sticky;
  bottom: 0;
}

Result:


This content originally appeared on DEV Community and was authored by Juan Belieni


Print Share Comment Cite Upload Translate Updates
APA

Juan Belieni | Sciencx (2021-08-24T23:50:29+00:00) How to create sticky headers and footers with CSS. Retrieved from https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/

MLA
" » How to create sticky headers and footers with CSS." Juan Belieni | Sciencx - Tuesday August 24, 2021, https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/
HARVARD
Juan Belieni | Sciencx Tuesday August 24, 2021 » How to create sticky headers and footers with CSS., viewed ,<https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/>
VANCOUVER
Juan Belieni | Sciencx - » How to create sticky headers and footers with CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/
CHICAGO
" » How to create sticky headers and footers with CSS." Juan Belieni | Sciencx - Accessed . https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/
IEEE
" » How to create sticky headers and footers with CSS." Juan Belieni | Sciencx [Online]. Available: https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/. [Accessed: ]
rf:citation
» How to create sticky headers and footers with CSS | Juan Belieni | Sciencx | https://www.scien.cx/2021/08/24/how-to-create-sticky-headers-and-footers-with-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.