Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide scrollbar with overflow:scroll enabled

I need to hide the scrollbar on a div that has overflow:scroll; enabled so that the div will scroll with mouse and keyboard but the scrollbar itself will not be displayed.

is there a way of doing this with css or is javascript the way to go?

like image 588
StephenJRomero Avatar asked Dec 03 '12 13:12

StephenJRomero


People also ask

How can I hide scrollbar in iframe but still scroll?

1. Set the overflow of the parent div as hidden. 2. Set the overflow of the child div to auto and the width 200% (or anything more than 100%, or more than the width of the parent - so that the scrollbar gets hidden).

How do you make the scrollbar only visible when overflow?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).

Does overflow hidden prevent scrolling?

To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element. This hides all content beyond the element's border.


2 Answers

You can do this with pure CSS (at least in webkit browsers). You have to use special scrollbar pseudo-classes to achieve this

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

Read this excellent blogpost for further information.

like image 179
Stephan Bönnemann-Walenta Avatar answered Oct 17 '22 22:10

Stephan Bönnemann-Walenta


You could put the scrolling div inside of a second div with overflow hidden, then just make the inner div a little wider and taller (the amount may vary depending on the browser, however).

Something like this:

#outer {
    overflow:hidden;
    width:200px; 
    height:400px;
    border:1px solid #ccc;
}
#inner {
    overflow:scroll; 
    width:217px; 
    height:417px;
}​

Full example at http://jsfiddle.net/uB6Dg/1/.

Edit: Unfortunately you can still get to the scrollbars by highlighting the text and dragging, and it does make padding etc a bit more of a pain, but other than this I think javascript is the way to go.

like image 26
Maloric Avatar answered Oct 18 '22 00:10

Maloric