$(window).height() doesn't seem exact

淺唱寂寞╮ 提交于 2019-12-11 15:07:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!