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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:42:40  来源:igfitidea点击:

How do I force a vertical scrollbar to appear?

cssmargin

提问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 bodytag 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 cssrule 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/