Html 使用溢出时无法隐藏滚动条:自动

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

can't hide scrollbar when using overflow: auto

htmlcss

提问by youmotherhaveapples

I have this CSS:

我有这个 CSS:

.div {
    background-color: red;
    position: relative;
    height: 414px;
    overflow: auto;
    width: 902px;
    margin: 0px auto;
}

I tried with overflow-y: hidden;, scrollbar disappear but scroll isn't working. Hope you understand what I want... Also, should I use auto or scroll? With auto I see horizontal bar too.

我试过overflow-y: hidden;,滚动条消失但滚动不起作用。希望你明白我想要什么......另外,我应该使用自动还是滚动?使用自动,我也看到了单杠。

Here is JSFiddle: http://jsfiddle.net/sp95S/
Thanks!

这是 JSFiddle:http: //jsfiddle.net/sp95S/
谢谢!

回答by user1121487

Create an inner div: http://jsfiddle.net/sp95S/1/

创建一个内部 div:http: //jsfiddle.net/sp95S/1/

.div {
    background-color: red;
    position: relative;
    height: 214px;
    overflow: hidden;
    width: 452px;
    margin: 0px auto;
}
#inner{
    width: 100%;
    overflow: auto;
    height: 100%;
    padding-right: 15px;
}

回答by ERose

It seems like you want to have the page still scroll without the scrollbar showing.

似乎您想让页面在不显示滚动条的情况下仍然滚动。

This has been answered here a couple of times already:

这已经在这里回答了几次:

Basically you can use javascript (or jquery, though you don't necessarily need it). On webkit browsers, there is a function to hide the scrollbars:

基本上你可以使用javascript(或jquery,虽然你不一定需要它)。在 webkit 浏览器上,有一个隐藏滚动条的功能:

::-webkit-scrollbar { 
display: none; 
}

but it won't work for firefox or internet explorer or opera.

但它不适用于 Firefox 或 Internet Explorer 或歌剧。

回答by Vigs

If you want to hide the scroll bar, but maintain scroll you can look into a plugin called slimscroll. The scroll bar is there but it can be configure to be rather un-noticable.

如果你想隐藏滚动条,但保持滚动,你可以查看一个名为slimscroll的插件。滚动条在那里,但可以将其配置为不显眼。

http://rocha.la/jQuery-slimScroll

http://rocha.la/jQuery-slimScroll