I was surprised I could not find a simple answer to this problem by Googling, but most responses to scrolling content panels either did not work properly, or did not work with bootstrap.
Answers like this one have full page scroll-bars, which seems wrong.
I am simply trying to have 100% height html
and body
with no browser scrollbar, but scrolling visible on the body content area only. It needs to behave with bootstrap menu heights etc.
So far the only way seems to work, at all, is using absolutely position content and footers elements.
html {
height: 100%;
}
html body {
height: 100%;
overflow: hidden;
}
html body .container-fluid.body-content {
position: absolute;
top: 50px;
bottom: 30px;
right: 0;
left: 0;
overflow-y: auto;
}
footer {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 30px;
}
But this just seems the wrong way to go about it and seems to impact Bootstrap layouts negatively. For instance, if the menu line wraps to two lines, the content area goes under the nav-bar div.
Can any please tell me the correct way to go about this styling, that is compatible with an out-of-the-box MVC Razor/Bootstrap application?
Notes:
- It needs to work with IE8 onwards.
- It needs to work with Bootstrap, so if Boostrap is adjusted (header/footer sizes) then it will correct itself too.
Update:
Here is a JSFiddle to work with (including my latest solution from answer below):
Another option would be using flexbox.
While it's not supported by IE8 and IE9, you could consider:
Despite some additional browser-specific style prefixing would be necessary for full cross-browser support, you can see the basic usage either on this fiddle and on the following snippet:
Until I get a better option, this is the most "bootstrappy" answer I can work out:
JSFiddle: http://jsfiddle.net/TrueBlueAussie/6cbrjrt5/
I have switched to using LESS and including the Bootstrap Source NuGet package to ensure compatibility (by giving me access to the bootstrap
variables.less
file:in _layout.cshtml master page
body-content
containernavbar-fixed-bottom
on the footer<hr/>
before the footer (as now redundant)Relevant page HTML:
In Site.less
HTML
andBODY
heights to 100%BODY
overflow
tohidden
body-content
divposition
toabsolute
body-content
divtop
to@navbar-height
instead of hard-wiring valuebody-content
divbottom
to30px
.body-content
divleft
andright
to 0body-content
divoverflow-y
toauto
Site.less
The remaining problem is there seems to be no defining variable for the
footer height
in bootstrap. If someone call tell me if there is a magic 30px variable defined in Bootstrap I would appreciate it.Add the following css to disable the default scroll:
And change the
#content
css to this to make the scroll only on content body:See fiddle here.
Edit:
Actually, I'm not sure what was the issue you were facing, since it seems that your css is working. I have only added the HTML and the header css statement: