Html 始终显示浏览器滚动条以防止页面跳转

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12582555/
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-29 03:02:18  来源:igfitidea点击:

Always show browser scrollbar to prevent page jumping

htmlcssbrowserscrollbar

提问by Paul

Possible Duplicate:
How to always show scrollbar in browser using javascript?

可能的重复:
如何使用 javascript 在浏览器中始终显示滚动条?

Some pages I have have lots of content other pages have a few lines, so when I am clicking between pages some pages have a scrollbar on the browsers and others don't. Because of this the page jumps all the time due to the extra space when clicking between pages.

有些页面我有很多内容,其他页面只有几行,所以当我在页面之间单击时,有些页面在浏览器上有滚动条,而其他页面没有。因此,由于在页面之间单击时有额外的空间,页面一直在跳转。

Is it possible to have the scrollbar visible at all times, or greyed out if there is not a lot of content to stop the jumping of pages?

是否可以让滚动条一直可见,或者如果没有很多内容来阻止页面跳转,滚动条会变灰?

Can it work across all browsers, hope someone can help,

它可以在所有浏览器上工作吗,希望有人能帮忙,

Cheers

干杯

回答by Oliver Millington

Try reading this articleby Chris Coyer, it explains it pretty well.

尝试阅读Chris Coyer 的这篇文章,它解释得很好。

From the article:

从文章:

Assigning overflow-y to scroll does work, and it works in Firefox, Safari, and IE 6, and that makes it the best solution:

将溢出-y 分配给滚动确实有效,它适用于 Firefox、Safari 和 IE 6,这使其成为最佳解决方案:

html {
    overflow-y: scroll; 
}

回答by Salketer

html {
    overflow-y: scroll; 
}

It is the best solution.

这是最好的解决方案。