Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple custom scrollbars

Tags:

css

scrollbar

All I want to know is if it is possible to have multiple custom made -webkit-scrollbars on the same page.. I making some divs color specific, like one div has green text and images and another blue etc. So I would like to make a custom scrollbar for each div so it matches the color..

Q1: Is it possible?

Q2: If so, how would I do it?

I have thought about one solution, but I think it is a bit cumbersome. One solution may be to make each div containing an iframe and then create separate pages with the unique scrollbars, but I don't know if that is going to work either..

like image 204
Corfitz. Avatar asked Apr 10 '26 09:04

Corfitz.


2 Answers

Of course you can - simply prepend the scrollbar pseudo-classes with your intended selectors, i.e.:

::-webkit-scrollbar-track {
    background-color: #333;
}

/* Override styles for <div>s, for example */
div::-webkit-scrollbar-track {
    background-color: #b13131;
}

I have made a simple example for you here - http://jsfiddle.net/teddyrised/Nsz93/

like image 153
Terry Avatar answered Apr 12 '26 23:04

Terry


You can also apply these rules by id of the element. Let's say scroll bar of a div has to be styled which has an id "myDivId". Then you can do following. This way you can use different styles for scroll bars of different elements.

#myDivId::-webkit-scrollbar {
    width: 12px;
}

#myDivId::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
    border-radius: 10px;
}

#myDivId::-webkit-scrollbar-thumb {
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}

http://jsfiddle.net/QcqBM/516/

like image 23
Pratik Patel Avatar answered Apr 12 '26 22:04

Pratik Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!