perhaps? 2013-05-21 13:11 采纳率: 100%
浏览 3302
已采纳

隐藏滚动条,但仍然能够滚动

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

在谷歌浏览器中:

::-webkit-scrollbar { 
    display: none; 
}
但是Mozilla Firefox和Internet Explorer似乎无法正常工作。 我也在CSS中尝试过:
overflow: hidden;

那确实隐藏了滚动条,但我无法滚动了。 有什么办法可以删除滚动条,同时仍然可以滚动整个页面? 仅使用CSS或HTML。请帮助我。

转载于:https://stackoverflow.com/questions/16670931/hide-scroll-bar-but-while-still-being-able-to-scroll

  • 写回答

23条回答

  • 衫裤跑路 2013-05-21 13:37
    关注

    Just a test which is working fine.

    #parent{
        height: 100%;
        width: 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:

    Since, the scrollbar width differs in different browsers, it is better to handle it with JavaScript. If you do Element.offsetWidth - Element.clientWidth, the exact scrollbar width will show up.

    JavaScript Working Fiddle

    or

    Using Position: absolute,

    #parent{
        height: 100%;
        width: 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

    Info:

    Based on this answer, I created a simple scroll plugin. I hope this will help someone.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(22条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?