javascript 更改 md-checkbox 颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32377276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change md-checkbox color
提问by Ellone
So it looks I can change the background-color of an empty md-checkbox
by doing :
所以看起来我可以md-checkbox
通过执行以下操作来更改空的背景颜色:
md-checkbox .md-icon {
background: red;
}
But I can't manage to change the background of a checked md-checkbox
.
I tried to play with :checked
, ::before
, ::after
... But didn't succeed.
但是我无法更改已检查的md-checkbox
. 我试着玩:checked
, ::before
, ::after
... 但没有成功。
How should I proceed ?
我应该如何进行?
采纳答案by dfsq
You need to use theme class as well as md-checked
class combination in order to define selector with higher specificity. For example:
您需要使用主题类以及md-checked
类组合来定义具有更高特异性的选择器。例如:
md-checkbox .md-icon {
background: red;
}
md-checkbox.md-default-theme.md-checked .md-icon {
background: orange;
}
And of course, avoid using !important
, this is a sign that something is wrong with your styles.
当然,避免使用!important
,这表明你的风格有问题。
回答by Stav Bodik
in new version added underscore ._md-icon:
在新版本中添加了下划线 ._md-icon:
md-checkbox.md-checked ._md-icon {
background-color: white;
}