How can I drop the CSS property ::-webkit-scrollbar
from a single HTML element?
In my CSS file, I have this code:
::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
::-webkit-scrollbar-track-piece {
background-color: blue;
}
::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
It will replace every scrollbar with webkit scrollbars. But there are two places where I don't need webkit scrollbar, I need normal scrollbars instead.
HTML file:
<td class="viewDialogLabel" height="21" style="width:156px;padding:0px">
<!-- Inner elements --->
</td>
Here, I need to change class viewDialogLabel
to normal scrollbars.
How do I get this effect?
We can use the CSS “::-webkit-scrollbar” property which is responsible for changing the shape, color, size, shade, shadow, etc. of the scroll bar. But, here the property which we will use is the direction property of CSS for changing the position of the scroll bar.
For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.
::-webkit-scrollbar is a pseudo-element in CSS employed to modify the look of a browser's scrollbar.
WebKit supports the handy CSS value initial
, which sets properties back to the values they would have had if no styles applied to the page.
So, you can reset the ::-webkit-scrollbar
values you’ve set like this:
.viewDialogLabel::-webkit-scrollbar {
width: initial;
height: initial;
background-color:initial;
}
.viewDialogLabel::-webkit-scrollbar-track {
background-color:initial;
width: initial;
}
.viewDialogLabel::-webkit-scrollbar-track-piece {
background-color: initial;
}
.viewDialogLabel::-webkit-scrollbar-thumb {
background-color: initial;
width: initial;
}
See http://jsfiddle.net/uVGKr/
WebKit also supports the :not()
selector, so I would have thought the following amendment to your original CSS would prevent the custom scrollbars from applying to that table cell:
:not(.viewDialogLabel)::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
:not(.viewDialogLabel)::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
:not(.viewDialogLabel)::-webkit-scrollbar-track-piece {
background-color: blue;
}
:not(.viewDialogLabel)::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
However, it doesn’t work for me in Chrome 16 — the custom scrollbar styles aren’t applied at all (see http://jsfiddle.net/uVGKr/1/). I’m not sure if I’m doing something wrong, if you just can’t combine these selectors, or if this is a WebKit bug.
As per your suggested edit removing the td
selectors from the CSS, this seems to be working in Chrome 24 at least: http://jsfiddle.net/uVGKr/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With