Can CSS be used to hide the scroll-bar? How would you do this?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
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 able to scroll with mouse/keyboard
Just thought I'd point out to anyone else reading this question that setting overflow: hidden (or overflow-y) on the body element didn't hide the scrollbars for me. I had to use the HTML element.
You can use the CSS property
overflow
and-ms-overflow-style
with a combination with::-webkit-scrollbar
.Tested on IE10+, Firefox, Safari and Chrome and works good:
This is a much better solution than the others when you hide the scrollbar with
padding-right
, because the default scrollbar width is different on each browser.Note: In the latest versions of Firefox the
-moz-scrollbars-none
property is deprecated ( link ).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.
Tested on a Samsung tablet with Android 4.0.4 (both in the native browser & Chrome) and on an iPad with iOS 6 (both in Safari & Chrome).
WebKit supports scrollbar pseudo elements that can be hidden with standard CSS rules:
If you want all scrollbars hidden, use
I'm not sure about restoring - this did work, but there might be a right way to do it:
You can of course always use
width: 0
, which can than be easily restored withwidth: auto
, but I'm not a fan of abusingwidth
for visibility tweaks.Update: Firefox 64 now supports the experimental scrollbar-width property by default (63 requires a config flag to be set). To hide the scrollbar in FF64:
To see if your current browser supports either the pseudo element or
scrollbar-width
, try this snippet:(Note that this is not really a correct answer to the question because it hides the horizontal bars as well, but that's what I was looking for when Google pointed me here, so I figured I'd post it anyway.)
I believe you can manipulate it with the overflow CSS attribute, but they have limited browser support. One source said it was IE5+, Firefox 1.5+, and Safari 3+ - maybe enough for your purposes.
This link has a good discussion: http://www.search-this.com/2008/03/26/scrolling-scrolling-scrolling/