问题
http://jsfiddle.net/WL5nr/1/
I have a div whose height is larger than the screen and I'm trying to eliminate the scrollbar and have it still fill the page (whatever size the page is). I set overflow: hidden
and then set the $(window).height()
but I'm still seeing a scroll bar.
Doing $(window).height() - 20
eliminates it but it doesn't seem like I should have to do that. And so maybe - 20
works in the jsfiddle.net window... what if the window is bigger?
回答1:
The window height does not take into account the margin that is by default applied to the body. If you eliminate this margin you should get the effect you want:
html, body {
margin: 0;
padding: 0;
}
回答2:
You didn't take into account the body's margin. See http://jsfiddle.net/zerkms/Hmw7M/
body {
padding: 0;
margin: 0;
}
来源:https://stackoverflow.com/questions/15469572/window-height-doesnt-seem-exact