import { Checkbox } from 'antd'
<Checkbox style={{ color: 'red', backgroundColor: 'black' }}>Dr John</Checkbox>
How to change the color of the check box not the label 'Dr John'? The above style only change the styles of the label not the check box?
I was able to dynamically change the checkbox's color using @humanbean's and This answer. Using var() function in css and providing the color in inline style of the component. Show activity on this post. Override the default antd checkbox classes in your css and provide the necessary attributes to custom it.
“:hover” is used to style the checkbox when user hovers over it. Notice that when the mouse pointer move over the checkbox the color of it changes to yellow. “:active” is used to style the checkbox when it is active. Notice that when click the checkbox it will first notice a red color and then the green color.
You can use simple css
.ant-checkbox-checked .ant-checkbox-inner {
background-color: red;
border-color: red;
}
const CustomCheckbox = styled(Checkbox)`
${props =>
props.backgroundColor &&
css`
& .ant-checkbox-checked .ant-checkbox-inner {
background-color: ${props.backgroundColor};
border-color: ${props.backgroundColor};
}
`}
`;
with styled-component package you can do something like this.
<CustomCheckbox backgroundColor='green' />
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