有没有办法覆盖 Ant design Switch 组件中的颜色
我需要在选中时覆盖 Antd Switch 组件上的默认蓝色(主色)并将其更改为红色。我有办法做到这一点吗?
我尝试过使用样式属性,但它不起作用。
i need to override the default blue (primary color) on Antd Switch Component when checked and change it to red color. is there a way i can do this?
i have tried using style attribute but it didnt work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用这样的内联样式更改背景颜色。
You can change the backgroundColor using inline styles like this.
您可以像这样重写
.ant-switch-checked
类You can override the
.ant-switch-checked
class like so更简洁的方法是使用 Ant Design (antd) 5 版本之后提供的官方主题。下面是一个示例:
A more concise way is utilizing the Ant Design (antd) official theme available after version 5. Here's an example:
我发现
当我做出反应表格setfieldvalue发生在此开关的其他地方时,做得并没有工作,所以我有
I found that doing
didnt quite work when i had react Form setFieldValue happening elsewhere to this switch so instead i have
您可以通过覆盖开关类的默认类(您将从开发人员工具中获取所有元素类)来更改开关样式,
因此它将全局覆盖颜色,要覆盖特定元素的颜色,只需将元素包装在某个 div 中给类“test”并覆盖CSS
,它只会更新特定元素的颜色。
you can change switch styling by overriding default class (you will get all the element classes from developer tool) for switch class
as a result it will override the color globally, to override the color for specific element only just wrap the element in some div by giving class "test" and override the css like
and it will update the color for specific elemet only.
在您的
main
/theme
文件中,您可以像这样覆盖变量:或者
您实际上可以覆盖您使用的任何变量:参考
In your
main
/theme
file, you can just override the variable like so:or
You can actually override any variables to your use: reference