How to always show the vertical scrollbar in a browser?

前端 未结 9 542
盖世英雄少女心
盖世英雄少女心 2020-12-01 01:42

I want to always show vertical scrollbar in my webpage. Is it possible using javascript? I think it is possible using javascript or jQuery. I want vertical scrollbar whether

相关标签:
9条回答
  • 2020-12-01 02:08

    Add the class to the div you want to be scrollable.

    overflow-x: hidden; hides the horizantal scrollbar. While overflow-y: scroll; allows you to scroll vertically.

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    .scroll {
        width: 500px;
        height: 300px;
        overflow-x: hidden; 
        overflow-y: scroll;
    }
    
    
    </style>
    </head>
    <body>
    
    <div class="scroll"><h1> DATA </h1></div>
    
    0 讨论(0)
  • 2020-12-01 02:10

    Tried to do the solution with:

    body {
      overflow-y: scroll;
    }
    

    But I ended up with two scrollbars in Firefox in this case. So I recommend to use it on the html element like this:

    html {
      overflow-y: scroll;
    }
    
    0 讨论(0)
  • 2020-12-01 02:12

    Just use CSS.

    body {
      overflow-y: scroll;
    }
    
    0 讨论(0)
  • 2020-12-01 02:12

    set the overflow property of a containing div to scroll.

    0 讨论(0)
  • 2020-12-01 02:15

    Just a note: In OS X Lion, overflow set to "scroll" behaves more like auto in that scrollbars will only show when being used. They will disappear when not in use. So if any the solutions above don't appear to be working that might be why.

    This is what you'll need to fix it:

    ::-webkit-scrollbar {
      -webkit-appearance: none;
      width: 7px;
    }
    ::-webkit-scrollbar-thumb {
      border-radius: 4px;
      background-color: rgba(0, 0, 0, .5);
      -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, .5);
    }
    

    You can style it accordingly.

    0 讨论(0)
  • 2020-12-01 02:16

    jQuery shouldn't be required. You could try adding the CSS:

    body    {overflow-y:scroll;}
    

    This works across the latest browsers, even IE6.

    0 讨论(0)
提交回复
热议问题