当使用“高度:100vh"时,对于容器,出现垂直滚动条 [英] When using "height: 100vh" for the container, vertical scrollbar appears
本文介绍了当使用“高度:100vh"时,对于容器,出现垂直滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望内容占据浏览器窗口的整个高度,但不要超过整个高度.
I want the content to take the full height of the browser window, but not beyond.
使用100vh作为容器高度时,我可以看到出现了垂直滚动条.
When using 100vh as the container height, I can see the vertical scrollbar appearing.
.container {
height: 100vh;
border: 3px solid lightsteelblue;
border-radius: 10px;
}
可能是什么问题?
更详细的代码:
CSS
html, body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
.container {
height: 100vh;
margin: 0px;
padding: 0px;
}
.page_content {
height: 85vh;
width: 95vw;
border: 3px solid lightsteelblue;
border-radius: 10px;
overflow-y: auto;
margin: 0 auto;
}
.footer {
height: 14vh;
width: 95vw;
margin: 0px auto;
padding: 0px;
}
HTML
<html>
<body>
<div class="container">
<div class="page_content">
...
</div>
<div class="footer">
...
</div>
</div>
</body>
</html>
推荐答案
默认情况下,将body
和html
分配给margin
或padding
某些像素.尝试使用以下代码.
By default body
and html
are assigned to margin
or padding
to some pixels. Try using following code.
1vh =速度端口高度的1% 100vh =高度的100%.
1vh = 1% of veiwport height 100vh = 100% of height.
所以永远不要计算高度-3px.像这样
So never calculate height - 3px. like this
body,html {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
这篇关于当使用“高度:100vh"时,对于容器,出现垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文