Hiding the scroll bar on an HTML page

前端 未结 21 1048
旧巷少年郎
旧巷少年郎 2020-11-22 00:07

Can CSS be used to hide the scroll bar? How would you do this?

相关标签:
21条回答
  • 2020-11-22 00:42

    This works for me with simple CSS properties:

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

    For older versions of Firefox, use: overflow: -moz-scrollbars-none;

    0 讨论(0)
  • 2020-11-22 00:42

    As the other people already said, use CSS overflow.

    But if you still want the user to be able to scroll that content (without the scrollbar being visible) you have to use JavaScript.

    Se my answer here for a solution: Hide scrollbar while still being able to scroll with mouse/keyboard

    0 讨论(0)
  • 2020-11-22 00:43

    My HTML is like this:

    <div class="container">
      <div class="content">
      </div>
    </div>
    

    Add this to your div where you want to hide the scrollbar:

    .content {
      position: absolute;
      right: -100px;
      overflow-y: auto;
      overflow-x: hidden;
      height: 75%; /* This can be any value of your choice */
    }
    

    And add this to the container

    .container {
      overflow-x: hidden;
      max-height: 100%;
      max-width: 100%;
    }
    
    0 讨论(0)
  • 2020-11-22 00:46

    I believe you can manipulate it with the overflow CSS attribute, but they have limited browser support. One source said it was Internet Explorer 5 (and later), Firefox 1.5 (and later), and Safari 3 (and later) - maybe enough for your purposes.

    Scrolling, Scrolling, Scrolling has a good discussion.

    0 讨论(0)
  • 2020-11-22 00:50

    If you're looking for a solution to hide a scrollbar for mobile devices, follow Peter's answer!

    Here's a jsfiddle, which uses the solution below to hide a horizontal scrollbar.

    .scroll-wrapper{
        overflow-x: scroll;
    }
    .scroll-wrapper::-webkit-scrollbar { 
        display: none; 
    }
    

    It was tested on a Samsung tablet with Android 4.0.4 (Ice Cream Sandwich, both in the native browser and Chrome) and on an iPad with iOS 6 (both in Safari and Chrome).

    0 讨论(0)
  • 2020-11-22 00:50

    In addition to Peter's answer:

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

    This will work the same for Internet Explorer 10:

     #element {
          -ms-overflow-style: none;
     }
    
    0 讨论(0)
提交回复
热议问题