CSS 禁用滚动

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

CSS Disabled scrolling

cssvertical-scrolling

提问by Sheff

I came across an issue with one of our web sites:

我在我们的一个网站上遇到了一个问题:

In IE9 the page had a vertical scrollbar, but you couldn't use the mousewheel, arrow keys, pgup/pgdwn to scroll. The only way to scroll was to actually click/hold and move the scrollbar.

在 IE9 中,页面有一个垂直滚动条,但您不能使用鼠标滚轮、箭头键、pgup/pgdwn 来滚动。滚动的唯一方法是实际单击/按住并移动滚动条。

I removed the following from the css:

我从 css 中删除了以下内容:

{
    overflow-x: hidden;
}

Then scrolling worked as usual. Has anyone else come across this? It seems odd as overflow-x should hide the horizontal scroll bar? Why would it effect the vertical?

然后滚动像往常一样工作。有没有其他人遇到过这个?看起来很奇怪,因为溢出-x 应该隐藏水平滚动条?为什么它会影响垂直?

I have tried this on a test page and it acts as expected. So it must be a combination of things.

我已经在测试页面上尝试过这个,它按预期运行。所以它必须是一个组合。

回答by Abhijit Sinha

Try using the following code snippet. This should solve your issue.

尝试使用以下代码片段。这应该可以解决您的问题。

body, html { 
    overflow-x: hidden; 
    overflow-y: auto;
}

回答by Martin

overflow-x: hidden;
would hide any thing on the x-axis that goes outside of the element, so there would be no need for the horizontal scrollbar and it get removed.

overflow-x: hidden;
会隐藏 x 轴上超出元素的任何东西,因此不需要水平滚动条,它会被删除。

overflow-y: hidden;
would hide any thing on the y-axis that goes outside of the element, so there would be no need for the vertical scrollbar and it get removed.

overflow-y: hidden;
将隐藏 y 轴上元素之外的任何内容,因此不需要垂直滚动条并将其删除。

overflow: hidden;
would remove both scrollbars

overflow: hidden;
将删除两个滚动条

回答by Roman

I use iFrame to insert the content from another page and CSS mentioned above is NOT working as expected. I have to use the parameter scrolling="no" even if I use HTML 5 Doctype

我使用 iFrame 从另一个页面插入内容,上面提到的 CSS 没有按预期工作。即使我使用 HTML 5 Doctype,我也必须使用参数 scrolling="no"