I'm working with Chakra UI and i needed to customize the scrollbar style using the css pseudo element ::-webkit-scrollbar
, but Chakra UI doesn't seen to have this pseudo element and a I don't know where I can style this specific component without creating a global css class.
Here is a sample of my code:
<Box
overflowX="auto"
maxW="100vw"
h="100%"
whiteSpace="nowrap"
pb="17px"
color="white"
px="32px"
// the ::-webkit-scrollbar property should goes here
>
<!-- content -->
</Box>
Note: ::-webkit-scrollbar is only available in Blink- and WebKit-based browsers (e.g., Chrome, Edge, Opera, Safari, all browsers on iOS, and others). A standardized method of styling scrollbars is available with scrollbar-color and scrollbar-width .
You can apply it by placing the overflow:scroll and white-space:nowrap in the id lifestyle inside the style tag. Notice the scroll bar at the bottom and right side of the div .
You need to add style="overflow-y:scroll;" to the div tag. (This will force a scrollbar on the vertical).
Try css prop:
<Box
overflowY="auto"
css={{
'&::-webkit-scrollbar': {
width: '4px',
},
'&::-webkit-scrollbar-track': {
width: '6px',
},
'&::-webkit-scrollbar-thumb': {
background: scrollbarColor,
borderRadius: '24px',
},
}}
>
Use Chakra sx
prop here.
<Box
overflowX="auto"
maxW="100vw"
h="100%"
whiteSpace="nowrap"
pb="17px"
color="white"
px="32px"
sx={
{
'::-webkit-scrollbar':{
display:'none'
}
}
}
>
<!-- content -->
</Box>
To know more about Chakra sx
prop, refer docs
its not gonna work with just css you need to __css
<Box
overflowY="auto"
__css={{
'&::-webkit-scrollbar': {
w: '2',
},
'&::-webkit-scrollbar-track': {
w: '6',
},
'&::-webkit-scrollbar-thumb': {
borderRadius: '10',
bg: `gray.100`,
},
}}
>
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