ChatGPT解决这个技术问题 Extra ChatGPT

隐藏滚动条,但仍然可以滚动

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

在谷歌浏览器中它是:

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

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

我也在 CSS 中试过这个:

overflow: hidden;

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

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

请仅使用 CSS 或 HTML。

webkit-scrollbar 在其他浏览器上不起作用吗?
添加 ::-webkit-scrollbar 正在更改数据结束部分的背景颜色。即使将 background-color 属性添加到白色,它也不会改变任何东西

C
Community

只是一个工作正常的测试。

#parent{
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#child{
    width: 100%;
    height: 100%;
    overflow-y: scroll;
    padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
    box-sizing: content-box; /* So the width will be 100% + 17px */
}

Working Fiddle

JavaScript:

由于不同浏览器的滚动条宽度不同,最好用 JavaScript 处理。如果您执行 Element.offsetWidth - Element.clientWidth,则会显示确切的滚动条宽度。

JavaScript Working Fiddle

或者

使用 Position: absolute

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

#child{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: -17px; /* Increase/Decrease this value for cross-browser compatibility */
    overflow-y: scroll;
}

Working Fiddle

JavaScript Working Fiddle

信息:

根据这个答案,我创建了一个 simple scroll plugin


在您的最后一个“工作小提琴”中,我看到了太多 !important,所以我将它们全部删除:jsfiddle.net/5GCsJ/954
这种方法不会涵盖所有浏览器,并且会非常特定于您在开发期间使用的浏览器版本。
为什么要复杂化和计算滚动条宽度?只需设置 box-sizing: border-box; width: calc(100% + 50px); 和相同的填充值。没有浏览器有 50px 的滚动条宽度/高度,所以它应该简单地覆盖它们......
j
joeybab3

这适用于我的简单 CSS 属性:

.container {
    -ms-overflow-style: none;  /* Internet Explorer 10+ */
    scrollbar-width: none;  /* Firefox */
}
.container::-webkit-scrollbar { 
    display: none;  /* Safari and Chrome */
}

对于旧版本的 Firefox,请使用:overflow: -moz-scrollbars-none;


对我来说,overflow: -moz-scrollbars-none 隐藏了 Firebox 中的滚动条,但也禁用了滚动。你能提供一个适合你的演示吗?
遗憾的是,最新 Firefox 版本的 -moz-scrollbars-none 属性已删除:developer.mozilla.org/en-US/docs/Web/CSS/overflow
从 iOS8 开始,这在与 -webkit-overflow-scrolling: touch 一起使用时不起作用
对于过时的 Firefox -moz-scrollbars-none,您可以使用 @-moz-document url-prefix() { .container { overflow: hidden; } }。请参阅stackoverflow.com/questions/952861/…
我已经用对 Firefox 的最新支持更新了我的答案:)
A
Artur INTECH

在 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;
}

cordova 应用中尝试过,效果很好。必须将 overflow:scroll 应用于元素。
不适用于 Firefox,很明显,因为这纯粹是针对 webkit。谢谢 :)
正如预期的那样在电子应用程序中表现出色,因为它们是铬的。 +1 谢谢:D
从 iOS8 开始,这在与 -webkit-overflow-scrolling: touch 一起使用时不起作用
它适用于铬。但不适用于 Mozilla firefox。
P
Peter Mortensen

更新:

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;
}

这是我目前知道的最简单的跨浏览器解决方案。 Check out the demo.

原始答案:

这是另一种尚未提及的方式。它非常简单,只涉及两个 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;
}

scrollbar-width: none 在 Firefox 91 中不起作用
@IterAtor 但它适用于我的版本(Firefox 97)
4
4 revs, 3 users 62%

利用:

<div style='overflow:hidden; width:500px;'>
   <div style='overflow:scroll; width:508px'>
      My scroll-able area
   </div>
</div>

这是将滚动条与没有任何滚动条的重叠 div 在某种程度上重叠的技巧:

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

这仅适用于 WebKit 个浏览器...或者您可以使用特定于浏览器的 CSS 内容(如果将来有的话)。每个浏览器都可以为其各自的栏具有不同的特定属性。

对于 Microsoft Edge,请使用:-ms-overflow-style: -ms-autohiding-scrollbar;-ms-overflow-style: none; 作为 per MSDN

Firefox 没有等价物。虽然有一个 jQuery 插件来实现这一点,http://manos.malihu.gr/tuts/jquery_custom_scrollbar.html


ictacademie.info/oussamaelbachiri 这个网站@Oussama Dobby 使用 media='screen' 和 '::-webkit-scrollbar' 属性作为 css
什么是特定的 css 属性?
hacky 布局或 jquery 是另一种选择
你的第一个解决方案给了我这个问题 s24.postimg.org/idul8zx9w/Naamloos.jpg 你说的hacky layout是什么意思@ArpitSingh
以下允许我在 iOS7 上使用 jQuery Mobile 1.4 在 Cordova 中启用本机滚动 & iOS8 // CSS ::-webkit-scrollbar { display: none; } .ui-content { -webkit-overflow-scrolling: touch; } // jQuery Mobile onMobileInit() $.mobile.touchOverflowEnabled = true;
e
eol

此外,适用于所有浏览器的无滚动条滚动。

CSS

.keep-scrolling {
  background-color: #eee;
  width: 200px;
  height: 100px;
  border: 1px dotted black;
  overflow-y: scroll; /* Add the ability to scroll y axis*/
}

/* Hide scrollbar for Chrome, Safari and Opera */
.keep-scrolling::-webkit-scrollbar {
    display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.keep-scrolling {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

SCSS

.keep-scrolling {
      background-color: #eee;
      width: 200px;
      height: 100px;
      border: 1px dotted black;
      overflow-y: scroll; /* Add the ability to scroll y axis*/

     /* Hide scrollbar for IE, Edge and Firefox */
      -ms-overflow-style: none;  /* IE and Edge */
      scrollbar-width: none;  /* Firefox */

      /* Hide scrollbar for Chrome, Safari and Opera */
      &::-webkit-scrollbar {
        display: none;
      }
    }
     

HTML

<div class="keep-scrolling">
</div>

缺少一个 &从 scss 版本:&::-webkit-scrollbar { display: none; }
A
Arthur

使用它来隐藏滚动条但保留功能:

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

隐藏 IE、Edge 和 Firefox 的滚动条

.example {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

这是国际海事组织的最佳答案。这是我发现如何隐藏滚动条同时保持提到的每个浏览器的功能的来源。 w3schools.com/howto/howto_css_hide_scrollbars.asp
P
Peter Mortensen

只需使用以下三行即可解决您的问题:

#liaddshapes::-webkit-scrollbar {
    width: 0 !important;
}

其中 liaddshapes 是滚动即将到来的 div 的名称。


告诉我你在小提琴中的问题
简单实用,谢谢!我使用 {display:none} 而不是 {width:0;} 并且也可以工作
P
Peter Mortensen

This answer 不包含代码,因此这是来自 page 的解决方案:

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

好消息是您不必被迫使用填充或宽度差异来隐藏滚动条。

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

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

.element, .outer-container { 宽度:200px;高度:200px; } .outer-container { 边框:5px 纯紫色;位置:相对;溢出:隐藏; } .inner-container { 位置:绝对;左:0;溢出-x:隐藏;溢出-y:滚动; padding-right: 150px; } .inner-container::-webkit-scrollbar { 显示:无; }

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vehicula quam nibh, eu tristique tellus dignissim quis。 Integer condimentum ultrices elit ut mattis。 Praesent rhoncus tortor metus,nec pellentesque enim mattis nec。 Nulla vitae turpis ut dui consectetur pellentesque quis vel est. Curabitur rutrum, mauris ut mollis lobortis, sem est congue lectus, ut sodales nunc leo a libero。在 mi fringilla tempus condimentum quis velit 中的 Cras quis sapien。 Aliquam id aliquam arcu。 Morbi tristique aliquam rutrum。 Duis tincidunt, orci suscipit cursus molestie, purus nisi pharetra dui, tempor dignissim felis turpis in mi。 Vivamus ullamcorper arcu sit amet mauris egestas egestas。 Vestibulum turpis neque, condimentum a tincidunt quis, molestie vel justo。 Sed molestie nunc dapibus arcu feugiat, ut sollicitudin metus sagittis。 Aliquam 一个 volutpat sem。 Quisque id magna ultrices、lobortis dui eget、pretium libero。 Curabitur aliquam 在 ante eu ultricies。


这不适用于所有浏览器......只有 webkit 浏览器。您正在使用特定于 webkit 的选择器 ::-webkit-scrollbar {}
在回答问题之前,我在所有新浏览器中都对其进行了测试。还有FF。 FF发生了一些变化?
我更新了答案。似乎添加 padding-right: 150px; 可以修复它。在 FF、Chrome、Safari 和 Edge 中测试。由于右填充大,也适用于低缩放级别。
Edge、IE 11、IE10(也可能更低)支持 html { -ms-overflow-style: none;}。在这些浏览器中,无需使用 padding-hack。
必须使用@Timo 的答案和overflow-y: scroll 来获得滚动行为但隐藏(就像 Chrome)以使其在 Edge23 上工作。
C
Community

这适用于我的跨浏览器。但是,这不会隐藏移动浏览器上的本机滚动条。

在 SCSS 中

.hide-native-scrollbar {
  scrollbar-width: none; /* Firefox 64 */
  -ms-overflow-style: none; /* Internet Explorer 11 */
  &::-webkit-scrollbar { /** WebKit */
    display: none;
  }
}

在 CSS 中

.hide-native-scrollbar {
  scrollbar-width: none; /* Firefox 64 */
  -ms-overflow-style: none; /* Internet Explorer 11 */
}
.hide-native-scrollbar::-webkit-scrollbar { /** WebKit */
  display: none;
}

嵌套块 ({}) 是什么意思?该如何解读? & 呢?也许在你的答案中详细说明?
这是 SASS 的事情(显然,LESS 也是):css-tricks.com/the-sass-ampersand
@PeterMortensen 我现在才看到您的评论,&::-webkit-scrollbar 在 CSS 中变为 .hide-native-scrollbar::-webkit-scrollbar { }
只需为 ::-webkit-scrollbar 执行 { width: 0; height: 0;} 而不是为 iOS 执行 display: none
在 FF71 中,这会阻止所有滚动。
V
Visal

只需编写以下代码:

::-webkit-scrollbar {
  width: 0px;
}

或者

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

R
Ramesh R
scrollbar-width: none; 

为我工作。


在我发布 caniuse.com/?search=scrollbar-width 时,不支持此跨浏览器
P
Peter Mortensen

以下内容适用于我在 Microsoft、Chrome 和 Mozilla 上针对特定 div 元素:

div.rightsidebar {
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
div.rightsidebar::-webkit-scrollbar { 
    width: 0 !important;
}

请注意,scrollbar-width(仅限 FF)被标记为“实验性”
是的@cimak,但是在FF上你可以隐藏它而没有任何问题,所以它真的只用于Chrome。
t
thwleitaba thabk
.className::-webkit-scrollbar{
    display: none;
}

你写的一切都是正确的,除了“溢出”。适用于 Chrome 和其他浏览器的 webkit

overflow-y: scroll;

或者

overflow-y: auto;

对于 Firefox 和 Edge

scrollbar-width: none;

或者

scrollbar-width: thin;

C
Chris

截至 2018 年 12 月 11 日(Firefox 64 及更高版本),这个问题的答案确实非常简单,因为 Firefox 64+ 现在实现了 CSS Scrollbar Styling spec

只需使用以下 CSS:

scrollbar-width: none;

Firefox 64 发行说明链接 here


很高兴知道这一点!看来浏览器确实在进步,哈哈!
A
Alvin Moyo

要隐藏内容溢出的元素的滚动条,请使用。

.div{

  scrollbar-width: none; /* The most elegant way for Firefox */

}    

除了你提到的 FF 之外,几乎不存在支持,对于 OP 的要求来说太少了。检查caniuse.com/#feat=mdn-css_properties_scrollbar-width
@Adrien好吧,原始问题表明他们有其他浏览器的解决方案。 (但 Mozilla Firefox 和 Internet Explorer 似乎不能那样工作)他说,这就是我提供 Firefox 解决方案的原因。
我发现与等效项结合使用时效果很好: div::-webkit-scrollbar { display: none; } 对于 Webkit / Chrome。
P
Peter Mortensen

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。

检查它here(在 Internet Explorer 和 Firefox 中测试)。


E
Eliran Assaraf

这对我有用

div {
  -ms-overflow-style: none; /* Edge, Internet Explorer */
  scrollbar-width: none; /* Firefox */
  overflow-y: scroll;
}

// hides scrollbars while allowing to scroll
div::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

C
Community

利用:

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>

不知道为什么这被否决了,但我只是对它投了赞成票,因为它确实朝着正确的方向发展,其他解决方案在我的情况下并没有真正奏效。溢出-x:隐藏; +溢出-y:滚动;诀窍是什么,以及> 100%的宽度(在我的情况下为110%效果很好)。
这与最受好评的解决方案相同:试图隐藏滚动条。这并不理想,因为它因浏览器而异
P
Peter Mortensen

在现代浏览器上,您可以使用 wheel event

// Content is the element you want to apply the wheel scroll effect to
content.addEventListener('wheel', function(e) {
    const step = 100; // How many pixels to scroll

    if (e.deltaY > 0) // Scroll down
        content.scrollTop += step;
    else // Scroll up
        content.scrollTop -= step;
});

这是我一直在寻找的答案。谢谢。我使用了 overflow: hidden 和这段代码,让 mat-card-content(当然是角度 5)可以滚动,这些解决了我的问题。注意:我使用 e.deltaY 作为我的 step,它就像正常滚动一样工作,所以我认为对于正常滚动但隐藏滚动条,这是最好的匹配。
此处链接的页面警告说这种方法不合适?
P
Peter Mortensen

利用

function reloadScrollBars() {
    document.documentElement.style.overflow = 'auto';  // Firefox, Chrome
    document.body.scroll = "yes"; // Internet Explorer only
}

function unloadScrollBars() {
    document.documentElement.style.overflow = 'hidden';  // firefox, chrome
    document.body.scroll = "no"; // Internet Explorer only
}

为您想要加载或卸载或重新加载滚动条的任何点调用这些函数。当我在 Chrome 中测试它时,它仍然可以在 Chrome 中滚动,但我不确定其他浏览器。


P
Peter Mortensen

这对我有用:

scroll-content {
    overflow-x: hidden;
    overflow-y: scroll;
}

scroll-content::-webkit-scrollbar {
    width: 0;
}

P
Peter Mortensen

这就是我为水平滚动做的方式;只有 CSS 并且适用于 Bootstrap / col-* 等框架。它只需要两个额外的 div 和具有 widthmax-width 集的父级:

如果您有触摸屏,您可以选择文本以使其滚动或用手指滚动。

.overflow-x-scroll-no-scrollbar { 溢出:隐藏; } .overflow-x-scroll-no-scrollbar div { 溢出-x:隐藏;边距底部:-17px;溢出-y:隐藏;宽度:100%; } .overflow-x-scroll-no-scrollbar div * { overflow-x: auto;宽度:100%;底部填充:17px;空白:nowrap; cursor: pointer } /* 以下类只是为了让示例看起来更好看 */ .row { width: 100% } .col-xs-4 { width: 33%;浮动:左 } .col-xs-3 { 宽度:25%;浮动:左 } .bg-gray { 背景色:#DDDDDD } .bg-orange { 背景色:#FF9966 } .bg-blue { 背景色:#6699FF } .bg-orange-light{ 背景色: #FFAA88 } .bg-blue-light{ background-color: #88AAFF }

第1列< /div>
第2列
第3列
< div class="row">
内容1
这个内容对于容器来说太长了,所以它需要隐藏但可以不滚动条滚动
内容3

懒人的简短版本:

.overflow-x-scroll-no-scrollbar { 溢出:隐藏; } .overflow-x-scroll-no-scrollbar div { 溢出-x:隐藏;边距底部:-17px;溢出-y:隐藏;宽度:100%; } .overflow-x-scroll-no-scrollbar div * { overflow-x: auto;宽度:100%;底部填充:17px;空白:nowrap; cursor:pointer } /* 下面的类只是为了让示例看起来更好看 */ .parent-style { width: 100px; background-color: #FF9966 }

这个内容对于容器来说太长了,所以它需要被隐藏但是可以在没有滚动条的情况下滚动


谢谢,我试过了,效果很好。一件事是最好将 margin-bottom 更改为 padding-bottom 但具有相同的值。这不会占用底部元素的空间。它可以防止重叠。
@haxpor margin-bottom 是负数,我认为它不能更改为 padding-bottom,不能处理负值
P
Peter Mortensen

我的问题:我不想在我的 HTML 内容中使用任何样式。我希望我的身体可以直接滚动,没有任何滚动条,只有垂直滚动,可以使用 CSS grids 处理任何屏幕尺寸。

box-sizing 值影响填充或边距解决方案,它们与 box-sizing:content-box 一起使用。

我仍然需要“-moz-scrollbars-none”指令,并且像 gdoron 和 Mr_Green 一样,我不得不隐藏滚动条。我尝试了 -moz-transform-moz-padding-start,只影响 Firefox,但有需要做太多工作的响应式副作用。

此解决方案适用于具有“显示:网格”样式的 HTML 正文内容,并且它是响应式的。

/* Hide HTML and body scroll bar in CSS grid context */
html, body {
  position: static; /* Or relative or fixed ... */
  box-sizing: content-box; /* Important for hidding scrollbar */
  display: grid; /* For CSS grid */

  /* Full screen */
  width: 100vw;
  min-width: 100vw;
  max-width: 100vw;
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  margin: 0;
  padding: 0;
}

html {
  -ms-overflow-style: none;  /* Internet Explorer 10+ */
  overflow: -moz-scrollbars-none; /* Should hide the scroll bar */
}

/* No scroll bar for Safari and Chrome */
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none; /* Might be enough */
  background: transparent;
  visibility: hidden;
  width: 0px;
}

/* Firefox only workaround */
@-moz-document url-prefix() {
  /* Make HTML with overflow hidden */
  html {
    overflow: hidden;
  }

  /* Make body max height auto */
  /* Set right scroll bar out the screen  */
  body {
    /* Enable scrolling content */
    max-height: auto;

    /* 100vw +15px: trick to set the scroll bar out the screen */
    width: calc(100vw + 15px);
    min-width: calc(100vw + 15px);
    max-width: calc(100vw + 15px);

    /* Set back the content inside the screen */
    padding-right: 15px;
  }
}

body {
  /* Allow vertical scroll */
  overflow-y: scroll;
}

A
Alexander

以下 SASS 样式应使您的滚动条在大多数浏览器上都是透明的(不支持 Firefox):

.hide-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;

  &::-webkit-scrollbar {
    width: 1px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background-color: transparent;
  }
}

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

P
Peter Mortensen

如果由于某种原因您想使用 box-model: border-box,则在当前接受的答案中向内部 div 添加填充将不起作用。

在这两种情况下起作用的是将内部 div 的宽度增加到 100% 加上滚动条的宽度(假设外部 div 上的 overflow: hidden)。

例如,在 CSS 中:

.container2 {
    width: calc(100% + 19px);
}

在 JavaScript 中,跨浏览器:

var child = document.getElementById('container2');
var addWidth = child.offsetWidth - child.clientWidth + "px";
child.style.width = 'calc(100% + ' + addWidth + ')';

A
Adam Ranganathan

我碰巧在我的项目中尝试了上述解决方案,但由于 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*/
}

P
Peter Mortensen

这将在正文中:

<div id="maincontainer" >
<div id="child">this is the 1st step</div>
<div id="child">this is the 2nd step</div>
<div id="child">this is the 3rd step</div>

这是CSS:

#maincontainer
{
    background: grey;
    width: 101%;
    height: 101%;
    overflow: auto;
    position: fixed;
}

#child
{
    background: white;
    height:500px;
}

P
Peter Mortensen

这是一个 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;
}