Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Layout Basics Getting Started with CSS Layout Creating a Sticky Footer

Viktor Jančík
Viktor Jančík
4,604 Points

Sticky Footer Overflow Auto

Hi, It seems adding (overflow: auto) to .container, makes your sticky footer example work. Without it the bottom margin of the last paragraph doesn't get included into the height of the (.wrap) container, which messes up the calculation. With (overflow: auto) however, it does get included.

Could you explain why overflow: auto does this and what is its purpose? From w3schools, it says it should cause a scrollbar to appear instead of this effect.

Thank you!

3 Answers

Did you use the workspace for this lesson, or carry over from the last one? I had this problem until I notice that Guil had added:

p:last-child {
  margin-bottom: 0;
}

to his css, thus removing the extra space between my wrap div and footer that was causing this problem.

Jeremiah Shore
Jeremiah Shore
31,168 Points

I did not use the workspace. I prefer to work locally on my PC using sublime text and chrome, which is what I use when i am working on real projects.

Thanks for pointing this out. Kinda silly how deep I looked into this for something that wasn't mentioned in the videos to resolve it.

Christopher Parke
Christopher Parke
21,978 Points

None of this worked for me.

```/* Page Styles ================================ */

body { font: normal 1.1em/1.5 sans-serif; color: #222; background-color: #edeff0; }

html, body, .main-wrapper, .col { height: 100%; overflow: auto; }

/* .main-wrapper { width: 90%; margin: auto; } */

  • { box-sizing: border-box; }

/* Layout Element Colors ================================ */

.main-header { background-color: #384047; } .main-logo { background-color: #5fcf80; } .main-nav li { background-color: #3f8abf; } .primary-content { background-color: #caebf6; } .secondary-content { background-color: #bfe3d0; } .main-footer { background-color: #b7c0c7; }

/* Header, Banner and Footer Layout ================================ */

.main-header { padding: 20px; display: table; width: 100%; min-height: 150px; }

.main-logo, .main-nav, .main-nav li { display: inline-block; }

.main-logo, .main-nav { display: table-cell; vertical-align: middle; }

.main-logo { width: 120px; }

.main-nav { padding-left: 50px; }

.main-logo, .main-nav li { border-radius: 5px; }

.main-nav li { margin-top: 15px; margin-right: 10px; }

.main-logo a, .main-nav a { color: white; text-decoration: none; display: block; text-align: center; padding: 10px 20px; }

.main-footer { text-align: center; padding: 20px; }

/*

Column Layout

*/

.col { display: inline-block; padding: 20px; margin-right: -5px; vertical-align: top; }

.primary-content { width: 60%; }

.secondary-content { width: 40%; }

/*

Media Queries

*/

@media (max-width: 768px) { .main-logo, .main-nav, .main-nav li { display: block; width: initial; margin: initial; }

.main-nav {
    padding-left: initial;
}

.main-nav li {
    margin-top: 15px;
}

}```

Christopher Parke
Christopher Parke
21,978 Points

lol even the markdown doesn't work as described in the cheatsheet.

Jeremiah Shore
Jeremiah Shore
31,168 Points

Thank you so much for pointing this out! No one else came close to recognizing this problem in their questions; nice catch! I'm not really sure how or why that affects the calculation. If you really wanted to you could probably read the RFC, but I can think of better ways to spend my time lol. I dug into this a little more, and I've put some details below.

The calc function as it is provided in this example is enough to remove the scroll bar in Mozilla Firefox 44.

Setting overflow: auto removes the scroll bar in Google Chrome 48. I inspected the bottom margin on the last paragraph, which is 16px. Commenting out overflow:auto and changing the min-height calc function from calc(100vh - 89px) to calc(100vh - 105px) had the same effect, because of the 16px difference.

Interestingly enough in Internet Exploder 11, the overflow:auto setting reduces the size of the scroll bar but does not remove it entirely. I checked and in both Chrome and IE the line height of the footer text is actually 25.6px. I am assuming this is interpreted differently in Chrome than IE. As a test, I commented out overflow:auto and then changed the calc function from calc(100vh - 89px) to calc(100vh - 106px), one 1px more to accommodate for that extra .6 px, and that was enough to make the scroll bar go away.

Looks like there is no exact way to get this to work uniformly across all the major browsers, but since overflow:auto works for Chrome and doesn't break anything for Firefox, I am going to STICK with that for sticky footers. With Chrome currently having 68% market share and Firefox 19%, that's good enough for me.

Thanks again!

Jeremiah Shore
Jeremiah Shore
31,168 Points

Applying a clear fix also works instead of using overflow:auto. Seems like that might be a better way, as applying overflow:auto to any sort of wrapper div might cause some unwanted behavior with its children.