Hide scroll bar, but while still being able to scroll

前端 未结 30 3120
悲哀的现实
悲哀的现实 2020-11-21 04:22

I want to be able to scroll through the whole page, but without the scrollbar being shown.

In Google Chrome it\'s:

::-webkit-scrollbar {
    display:         


        
相关标签:
30条回答
  • 2020-11-21 04:47

    Use:

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

    This is a trick to somewhat overlap the scrollbar with an overlapping div which doesn't have any scroll bars:

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

    This is only for WebKit browsers... Or you could use browser-specific CSS content (if there is any in future). Every browser could have a different and specific property for their respective bars.

    For Microsoft Edge use: -ms-overflow-style: -ms-autohiding-scrollbar; or -ms-overflow-style: none; as per MSDN.

    There is no equivalent for Firefox. Although there is a jQuery plugin to achieve this, http://manos.malihu.gr/tuts/jquery_custom_scrollbar.html

    0 讨论(0)
  • 2020-11-21 04:49

    The following was working for me on Microsoft, Chrome and Mozilla for a specific div element:

    div.rightsidebar {
        overflow-y: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    div.rightsidebar::-webkit-scrollbar { 
        width: 0 !important;
    }
    
    0 讨论(0)
  • 2020-11-21 04:49

    This is a divitis-esque solution which nontheless should work for all browsers...

    The markup is as follows and needs to be inside something with relative positioning (and its width should be set, for example 400 pixels):

    <div class="hide-scrollbar">
        <div class="scrollbar">
            <div class="scrollbar-inner">
    
            </div>
        </div>
    </div>
    

    The 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;
    }
    
    0 讨论(0)
  • 2020-11-21 04:50

    Use this to hide the scrollbar but keep functionality:

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

    Hide scrollbar for IE, Edge and Firefox

    .example {
      -ms-overflow-style: none;  /* IE and Edge */
      scrollbar-width: none;  /* Firefox */
    }
    
    0 讨论(0)
  • 2020-11-21 04:50

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

    Apply CSS accordingly.

    Check it here (tested in Internet Explorer and Firefox).

    0 讨论(0)
  • 2020-11-21 04:50

    In addition, Scrolling without scroll bar for all browsers.

    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>
    
    0 讨论(0)
提交回复
热议问题