Given this div:
<div style="overflow:auto;"></div>
How can I make the scrollbars visible only when the mouse is over the div?
I don’t want the scrollbars to always appear. Facebook’s right-top corner is an example of this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can make overflow hidden until the mouse is over it, then make it auto.
This is what I did … note the 16px padding assumes a scrollbar is 16px wide, and is there so the text doesn’t re-wrap when the scrollbar appears.
See it in action at this fiddle – you’ll want to widen the right side “result” window to see the whole box, or reduce the width in the css.
Edit 2014-10-23
There is now more variation in how systems and browsers display scrollbars, so my
16pxspace may need to be adjusted for your case. The intent of that padding is to prevent the text from being re-flowed as the scrollbar appears and disappears.Some systems, such as newer versions of Mac OS X (10.8.x at least), don’t show scrollbars until you start scrolling which could throw this whole technique off. If the scrollbar doesn’t show you may have no reason to hide it until hover, or you may want to leave overflow as
autoor evenscrollrather than toggling it.