我希望能够滚动整个页面,但不显示滚动条。

在Google Chrome中,它是:

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

但Mozilla Firefox和Internet Explorer似乎不是这样工作的。

我也在CSS中尝试过:

overflow: hidden;

这确实隐藏了滚动条,但我不能再滚动了。

有没有一种方法可以删除滚动条,同时仍然可以滚动整个页面?

请只使用CSS或HTML。


当前回答

您可以使用下面的代码隐藏滚动条,但仍可以滚动:

.element::-webkit-scrollbar { 
    width: 0 !important 
}

其他回答

我碰巧在我的项目中尝试了上述解决方案,由于某些原因,由于div定位,我无法隐藏滚动条。因此,我决定通过引入一个表面覆盖滚动条的div来隐藏滚动条。下面的示例适用于水平滚动条:

<div id="container">
  <div id="content">
     My content that could overflow horizontally
  </div>
  <div id="scroll-cover">
     &nbsp; 
  </div>
</div>

对应的CSS如下:

#container{
   width: 100%;
   height: 100%;
   overflow: hidden;
   position: relative;
}

#content{
  width: 100%;
  height: 100%;
  overflow-x: scroll;
}
#scroll-cover{
  width: 100%;
  height: 20px;
  position: absolute;
  bottom: 0;
  background-color: #fff; /*change this to match color of page*/
}

这个答案不包括代码,所以下面是第页的解决方案:

根据页面的说法,这种方法不需要提前知道滚动条的宽度就可以工作,而且解决方案也适用于所有浏览器,可以在这里看到。

好的是,您不必使用填充或宽度差异来隐藏滚动条。

这也是缩放安全的。填充/宽度解决方案在缩放到最小值时显示滚动条。

Firefox修复程序:http://jsbin.com/mugiqoveko/1/edit?output

要素.外部容器{宽度:200px;高度:200px;}.外部容器{边框:5px纯紫色;位置:相对;溢出:隐藏;}.内部容器{位置:绝对;左:0;overflow-x:隐藏;overflow-y:滚动;右填充:150px;}.内部容器::-webkit滚动条{显示:无;}<div class=“outer container”><div class=“内部容器”><div class=“element”>Lorem ipsum dolor坐amet,consectetur adipiscing elit。整数车辆quam nibh,eu tristique tellus dignissim quis。整体调味品ultrices elit ut mattis。Praesent rhoncus tortor metus,nec pellentesque enim mattis nec。Nulla vitae turpis utdui consectetur pellentesque quis vel est。Curabitur rutrum,mauris ut mollis lobortis,sem est congue lectus,ut sodales nunc leo a libero。克雷斯·萨皮恩(Cras quis sapien)在米弗利利亚·坦普斯(mi frigilla tempus)调味品奎斯·韦利特(quis velit)中。Aliquam和Aliquam arcu。Morbi三体阿利奎姆·鲁特鲁姆(aliquam rutrum)。杜伊斯·廷西杜特(Duis tincidunt)、兽人(orci suscipit cursus interstie)、普鲁斯·尼西·法雷特拉(purus nisi phareta dui)、米的迪格尼斯·菲利斯·图比斯(tempor dignissim felis turpis)。Vestibulum turpis neque,调味品,调戏维尔·茹斯托。不要骚扰我,不要骚扰我。还有一个巨大的sem。Quisque id magna ultrices,lobortis dui eget,pretium libero。在未成年人之前,库拉比特人(Curabitur aliquam)。</div></div></div>

Use:

CSS

#subparent {
    overflow: hidden;
    width: 500px;
    border: 1px rgba(0, 0, 0, 1.00) solid;
}

#parent {
    width: 515px;
    height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 10%;
}

#child {
    width: 511px;
    background-color: rgba(123, 8, 10, 0.42);
}

HTML

<body>
    <div id="subparent">
        <div id="parent">
            <div id="child">
                <!- Code here for scroll ->
            </div>
        </div>
     </div>
</body>

这个棘手的解决方案甚至可以在旧的Internet Explorer web浏览器上使用。

这是[垂直滚动条]的变通方法

<html>

<head>
  <style>
    html,
    body {
      overflow: -moz-scrollbars-vertical;
      overflow-x: hidden;
      overflow-y: hidden;
      height: 100%;
      margin: 0;
    }
  </style>
</head>

<body id="body" style="overflow:auto;height:100%" onload="document.getElementById('body').style.width=document.body.offsetWidth+20+'px'">
  <!--your stuff here-->
</body>

</html>

试试看:jsfiddle

.your-overflow-scroll-class::-webkit-scrollbar {
  ...
  width: 0.5rem; //only hide the vertical scrollbar
  height: 0px; //only hide the horizontal scrollbar
}