How can I customize a scroll bar via CSS (Cascading Style Sheets) for one div
and not the whole page?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
gave me a nice mobile/osx like one.
There is a way by which you can apply custom scrollbars to custom div elements in your HTML documents. Here is a an example which helps. https://codepen.io/adeelibr/pen/dKqZNb But as a gist of it. You can do something like this.
CSS file looks like this.
I thought it would be helpful to consolidate the latest information on scroll bars, CSS, and browser compatibility.
Scroll Bar CSS Support
Currently, there exists no cross-browser scroll bar CSS styling definitions. The W3C article I mention at the end has the following statement and was recently updated (10 Oct 2014):
Microsoft
As others have mentioned, Microsoft supports scroll bar styling, but only for IE8 and above.
Example:
Chrome & Safari (WebKit)
Similarly, WebKit now has its own version:
From Custom scrollbars in WebKit, relevant CSS:
Firefox (Gecko)
Firefox does not have its own version of scroll bar styles according to this SO answer.
Cross-browser Scroll Bar Styling
JavaScript libraries and plug-ins can provide a cross-browser solution. There are many options.
The list could go on. Your best bet is to search around, research, and test the available solutions. I am sure you will be able to find something that will fit your needs.
Prevent Illegal Scroll Bar Styling
Just in case you want to prevent scroll bar styling that hasn't been properly prefixed with "-vendor", this article over at W3C provides some basic instructions. Basically, you'll need to add the following CSS to a user style sheet associated with your browser. These definitions will override invalid scroll bar styling on any page you visit.
Duplicate or Similar Questions / Source Not Linked Above
Note: This answer contains information from various sources. If a source was used, then it is also linked in this answer.
Custom scroll bars aren't possible with CSS, you'll need some JavaScript magic.
Some browsers support non-spec CSS rules, such as
::-webkit-scrollbar
in Webkit but is not ideal since it'll only work in Webkit. IE had something like that too, but I don't think they support it anymore.I tried a lot of plugins, most of them don't support all browsers, I prefer iScroll and nanoScroller works for all these browsers :
But iScroll do not work with touch!
demo iScroll : http://lab.cubiq.org/iscroll/examples/simple/
demo nanoScroller : http://jamesflorentino.github.io/nanoScrollerJS/
Like many people, I was looking for something that was:
...But alas - nothing!
Well if a job's worth doing... I was able to get something up and running in about 30 mins. Disclaimer: there's quite a few known (and probably a few as yet unknown) problems with it, but it makes me wonder what on Earth the other 2920 lines of JS are there for in many offerings!