CSS 如何强制显示垂直滚动条?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24700184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I force a vertical scrollbar to appear?
提问by Bakabaka
My site has both very short and longer pages. Since I center it in the viewport with margin: 0 auto
, it jumps around a few pixels when switching from a page that has a scrollbar to one that hasn't and the other way around.
我的网站有很短和较长的页面。由于我使用 将其居中在视口中margin: 0 auto
,因此当从具有滚动条的页面切换到没有滚动条的页面时,它会跳动几个像素,反之亦然。
Is there a way to force the vertical scrollbar to always appear, so my site stays put when browsing it?
有没有办法强制垂直滚动条始终出现,以便我的网站在浏览时保持不变?
回答by John Conde
Give your body
tag an overflow: scroll;
给你的body
标签overflow: scroll;
body {
overflow: scroll;
}
or if you only want a vertical scrollbar use overflow-y
或者如果您只想使用垂直滚动条 overflow-y
body {
overflow-y: scroll;
}
回答by Bakabaka
html { overflow-y: scroll; }
This css
rule causes a vertical scrollbar to always appear.
此css
规则会导致始终出现垂直滚动条。
Source: http://css-tricks.com/snippets/css/force-vertical-scrollbar/
来源:http: //css-tricks.com/snippets/css/force-vertical-scrollbar/