Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Footer's width is not 100% when browser window is resized

Tags:

html

css

I have two div's. One that's the body of my page and other that's the footer of my page. The footer div should have 100% of width, even when I resize browser window.

My webpage is in this way:

enter image description here

When I resize browser window the scroll appears:

enter image description here

If I scroll the page horizontally, my footer isn't 100% of width anymore:

enter image description here

What should I do to keep my footer div always 100% of width?

<body>
    <div id="header"></div>
    <div id="footer"></div>
</body>

#header {
    height: 500px;
    width: 1100px;
    margin: 0 auto;
    background: grey;
}

#footer {
    background: #6B191C;
    position: absolute;
    left: 0;
    height: 100px;
    width: 100%;
    margin-top: 60px;
}
like image 353
Pedro Estevao Avatar asked Oct 19 '22 04:10

Pedro Estevao


2 Answers

I just find a solution here: http://www.impressivewebs.com/fluid-header-footer-problem/

Setting a min-width to the footer with the same width of the main div (1100px).

I changed the css of my footer to this:

#footer {
    background: #6B191C;
    height: 100px;
    margin-top: 60px;
    min-width: 1100px;
}

And added some properties to the body:

body {
    width: 100%;
    margin: auto;
}

This link shows a webpage with this problem and another one with the solution applied: http://www.impressivewebs.com/demo-files/fluid-header-footer/

like image 135
Pedro Estevao Avatar answered Oct 21 '22 22:10

Pedro Estevao


Use vw instead of %. 1vh equals to 1% of browsers viewport.

#footer {
    background: #6B191C;
    position: absolute;
    left: 0;
    height: 100px;
    width: 100vw;
    margin-top: 60px;
}

There are more relative lengths than just vw. There is:

  • vh - Relative to 1% of the height of the viewport
  • vw - Relative to 1% of the width of the viewport
  • vmin - Relative to 1% of viewport's smaller dimension
  • vmax - Relative to 1% of viewport's larger dimension

source: https://developer.mozilla.org/en-US/docs/Web/CSS/length

like image 26
Kyrbi Avatar answered Oct 21 '22 23:10

Kyrbi