CSS 如何为特定 div 启用滚动并禁用页面滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18411215/
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 to Enable scroll for specific div and disable scroll for page
提问by Caspert
Is it possible to disable scroll for the page, and only enable for a specific div
inside the page?
是否可以禁用页面滚动,而只启用div
页面内的特定内容?
回答by Tatarin
to disable it use:
禁用它使用:
css
css
.disableScroll{
overflow-y:hidden;
overflow-x:hidden;
}
just add <body class="disableScroll">
to the disable
只需添加<body class="disableScroll">
到禁用
inline style<body style="overflow:hidden">
内联样式<body style="overflow:hidden">
for div use, leave scrolling enabled <div style="overflow:auto;">
对于 div 使用,启用滚动 <div style="overflow:auto;">
Keep in mind that you can use overflow-y for vertical scroll and overflow-x for horizontal scroll properties
请记住,您可以将溢出-y 用于垂直滚动,将溢出-x 用于水平滚动属性
回答by patrick
回答by patrick
for whole page:
对于整个页面:
body {
height: 100%;
width: 100%;
}
for div for example:
以 div 为例:
div.scroll {
width:180px;
height:170px;
overflow:auto;
}
in html:
在 html 中:
<div class='scroll'></div>
回答by Joe Mike
HTML:
HTML:
<div class="scrollDisable"></div>
CSS:
CSS:
.scrollDisable{
overflow-y:hidden;
overflow-x:hidden;
}
}
For whole page :
对于整个页面:
body {
height: 100%;
width: 100%;
}
Hope this will be helpful.
希望这会有所帮助。