Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Footer Fixed Width, Bottom of screen, and centred

Tags:

html

css

footer

I'm an iPhone Developer mainly, I'm a bit rubbish at CSS and I'm trying to make a webpage for my app.

I want to make my footer have the following properties:

  • Fixed width of 640px
  • Centered
  • Attached to bottom of screen, not page. So when the user resizes the window, the footer is always at the bottom

All the other styling I can do myself, it's just positional styling that I find really difficult.

Can someone please explain to me how to do this in just CSS.

like image 904
Alex Coplan Avatar asked Aug 12 '11 11:08

Alex Coplan


People also ask

How do I keep the footer span at the bottom of the page?

Set the padding of the footer to add whitespace between the content bottom and the window bottom. Create a container div that wraps the body content with position: relative; min-height: 100%; Add bottom padding to the main content div that is equal to the height plus padding of the footer.

How do I make the footer stick to the bottom of the screen?

Set margin on the footer Because you set the Body — the footer's parent element — to Flex, you can set the top margin on the footer element to Auto. This makes the footer push away from the content above, causing the footer to stick to the bottom of the page.


2 Answers

footer {
    width: 640px;
    margin: 0% -320px;
    position: fixed;
    left: 50%;
    bottom: 0%;
}

Example: http://jsbin.com/imisig/3

Example with heaps of text: http://jsbin.com/imisig/4

like image 129
Delan Azabani Avatar answered Sep 23 '22 05:09

Delan Azabani


Put the footer HTML into a <div id="footer">. And the CSS would be something like this:

#footer {
    width: 640px;
    position: fixed;
    bottom: 0px;
    left: 50%;
    margin-left: -320px;
}

Explanation

  • The width property sets the width to 640px
  • position: fixed will make it so it scrolls with the page
  • bottom: 0px makes it fixed on the bottom of the page (distance to bottom = 0px)
  • left: 50% puts the left side of the div to the center of the page
  • margin-left: -320px - now we have to move it 320px from the left to make it centered
like image 26
tskuzzy Avatar answered Sep 22 '22 05:09

tskuzzy