I have the following code that stopped working after the new Chrome update. How can I achieve cross-browser scrollbar styling?
// Note: Shared Scrollbar Style
const scrollbarSharedStyle = {
scrollbarColor: `${themeLayers.scrollBar[0]} ${themeLayers.scrollBar[1]}`,
'&::-webkit-scrollbar, & *::-webkit-scrollbar': {
backgroundColor: `${themeLayers.scrollBar[1]}`,
width: 12,
},
'&::-webkit-scrollbar-thumb, & *::-webkit-scrollbar-thumb': {
borderRadius: 6,
backgroundColor: `${themeLayers.scrollBar[0]}`,
minHeight: 24,
border: `2.5px solid ${themeLayers.scrollBar[1]}`,
},
'&::-webkit-scrollbar-thumb:focus, & *::-webkit-scrollbar-thumb:focus': {
backgroundColor: `${themeLayers.scrollBar[0]}`,
},
'&::-webkit-scrollbar-thumb:active, & *::-webkit-scrollbar-thumb:active': {
backgroundColor: `${themeLayers.scrollBar[0]}`,
},
'&::-webkit-scrollbar-thumb:hover, & *::-webkit-scrollbar-thumb:hover': {
backgroundColor: `${themeLayers.scrollBar[0]}`,
},
'&::-webkit-scrollbar-corner, & *::-webkit-scrollbar-corner': {
backgroundColor: `${themeLayers.scrollBar[1]}`,
},
};
2
Answers
You need to find the css "scrollbar-width" and "scrollbar-color".
Don’t apply them to Chrome.
You might consider
Chrome 121 update included the support for
scrollbar-width
andscrollbar-color
properties, which, when used, disable::-webkit-scrollbar
type of properties, according to MDN Docs.MDN note
The fix is to wrap the use of
scrollbar-width
andscrollbar-color
with@supports not selector(::-webkit-scrollbar) {}
.