Html 如何使页面不可滚动?

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

How to make a page unscrollable?

htmlcssscroll

提问by AaronAAA

I have a page I'm working on that encompasses a vertical drop-down menu. However, when the menu drops down, it pushes the text below it downwards and off the page. This is expected, but this enables the scroll bar on the side of the page. I was wondering it there was a way to get rid of this. In other words, it shouldn't just not scroll, but never even offer the option to scroll.

我有一个我正在处理的页面,其中包含一个垂直下拉菜单。但是,当菜单下拉时,它会将其下方的文本向下推离页面。这是意料之中的,但这会启用页面一侧的滚动条。我想知道有没有办法摆脱这种情况。换句话说,它不应该只是不滚动,甚至不应该提供滚动选项。

Thanks!

谢谢!

回答by khaverim

If you want no scrollbar to appear and no scrolling whatsoever to occur, in the CSS for the divin which you contain said dropdown use

如果您不希望出现滚动条并且不希望发生任何滚动,请在div包含所述下拉列表的 CSS中使用

overflow: hidden;

This will cut off any 'additional content' though; see an example here

不过,这将切断任何“附加内容”;在这里看到一个例子

回答by Randall Ma

Use overflow: hidden;on the element you want to hide the scrollbar on.

使用overflow: hidden;要隐藏滚动条上的元素。