我希望能够滚动整个页面,但不显示滚动条。
在Google Chrome中,它是:
::-webkit-scrollbar {
display: none;
}
但Mozilla Firefox和Internet Explorer似乎不是这样工作的。
我也在CSS中尝试过:
overflow: hidden;
这确实隐藏了滚动条,但我不能再滚动了。
有没有一种方法可以删除滚动条,同时仍然可以滚动整个页面?
请只使用CSS或HTML。
我希望能够滚动整个页面,但不显示滚动条。
在Google Chrome中,它是:
::-webkit-scrollbar {
display: none;
}
但Mozilla Firefox和Internet Explorer似乎不是这样工作的。
我也在CSS中尝试过:
overflow: hidden;
这确实隐藏了滚动条,但我不能再滚动了。
有没有一种方法可以删除滚动条,同时仍然可以滚动整个页面?
请只使用CSS或HTML。
当前回答
我遇到了这个问题,解决起来非常简单。
取两个容器。内部将是可滚动的容器,外部显然将容纳内部:
#inner_container { width: 102%; overflow: auto; }
#outer_container { overflow: hidden }
它非常简单,适用于任何浏览器。
其他回答
这个答案不包括代码,所以下面是第页的解决方案:
根据页面的说法,这种方法不需要提前知道滚动条的宽度就可以工作,而且解决方案也适用于所有浏览器,可以在这里看到。
好的是,您不必使用填充或宽度差异来隐藏滚动条。
这也是缩放安全的。填充/宽度解决方案在缩放到最小值时显示滚动条。
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>
在WebKit中使用可选样式很简单:
html {
overflow: scroll;
overflow-x: hidden;
}
::-webkit-scrollbar {
width: 0; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}
/* Optional: show position indicator in red */
::-webkit-scrollbar-thumb {
background: #FF0000;
}
更新:
Firefox现在支持使用CSS隐藏滚动条,因此所有主要浏览器(Chrome、Firefox、Internet Explorer、Safari等)都已覆盖。
只需将以下CSS应用于要删除滚动条的元素:
.container {
overflow-y: scroll;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* Internet Explorer 10+ */
}
.container::-webkit-scrollbar { /* WebKit */
width: 0;
height: 0;
}
这是我目前所知的最简单的跨浏览器解决方案。查看演示。
原始答案:
这是另一种尚未提及的方式。它非常简单,只涉及两个div和CSS。不需要JavaScript或专有CSS,它适用于所有浏览器。它也不需要显式设置容器的宽度,从而使其成为流体。
此方法使用负边距将滚动条移出父级,然后使用相同的填充量将内容推回到其原始位置。该技术适用于垂直、水平和双向滚动。
演示:
竖的水平的两个方向
垂直版本的示例代码:
HTML格式:
<div class="parent">
<div class="child">
Your content.
</div>
</div>
CSS:
.parent {
width: 400px;
height: 200px;
border: 1px solid #AAA;
overflow: hidden;
}
.child {
height: 100%;
margin-right: -50px; /* Maximum width of scrollbar */
padding-right: 50px; /* Maximum width of scrollbar */
overflow-y: scroll;
}
HTML格式:
<div class="parent">
<div class="child">
</div>
</div>
CSS:
.parent{
position: relative;
width: 300px;
height: 150px;
border: 1px solid black;
overflow: hidden;
}
.child {
height: 150px;
width: 318px;
overflow-y: scroll;
}
相应地应用CSS。
在这里检查(在Internet Explorer和Firefox中测试)。
这是一个类似于divitis的解决方案,所有浏览器都可以使用它。。。
标记如下所示,需要位于具有相对定位的内部(其宽度应设置为400像素):
<div class="hide-scrollbar">
<div class="scrollbar">
<div class="scrollbar-inner">
</div>
</div>
</div>
CSS:
.hide-scrollbar {
overflow: hidden;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.scrollbar {
overflow-y: scroll;
position: absolute;
top: 0;
left: 0;
right: -50px;
bottom: 0;
}
.scrollbar-inner {
width: 400px;
}