Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - how to style a footer

Tags:

css

is there a way to style a footer, so when there is a content (more than the height of the browser) it will be at bottom of the page(hidden), but if there is not enough content it will stick at bottom edge of the browser?

like image 761
Pavel Avatar asked Oct 04 '13 23:10

Pavel


People also ask

How do I style header and footer in CSS?

Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.

How do you style a footer in text?

On the status bar, click the Page Layout View button. Select the header or footer text you want to change. On the Home tab in the Font group, set the formatting options that you want to apply to the header / footer.


2 Answers

One solution I use requires a known height of your footer.

Fiddles:

A lot of content

A little content

Here's the HTML:

<main>
  hello
</main>
<footer>
  i am the footer
</footer>

And here's the CSS:

html, body {
    height: 100%;
}
main {
    min-height: 100%;
    margin-bottom: -100px;
    background: #ddd;
}
main:after {
    content: "";
    display: block;
    height: 100px;
}
footer {
    height: 100px;
    background: #eee;
}

The trick is to set the main part of your document to have a min-height of 100%. This element must contain everything else on your page. In my example, I used the main element for this.

Next, give this element a negative margin equal to the height of the footer. This moves it up just enough to leave room for the footer there at the bottom.

The last piece of the puzzle is the after element. This is required to fill the space of that negative margin. Otherwise, the content of the main will overflow into the footer.

like image 186
jamesplease Avatar answered Sep 27 '22 20:09

jamesplease


I can only recommend to read this.
Show footer if at bottom of page or page is short else hide

or this
http://css-tricks.com/snippets/css/fixed-footer/

like image 43
ummahusla Avatar answered Sep 27 '22 19:09

ummahusla