使用复选框类型更改开关标签的背景颜色?

时间:2016-07-17 19:25:43

标签: css materialize

所以我在我的网站上使用materializecss框架,我尝试添加一个看到的here。但是我在更改激活开关的颜色方面遇到了麻烦。它使用复杂的CSS,至少对我而言。

.switch label input[type=checkbox]:checked + .lever {
  background-color: #84c7c1;
}

例如,如此处所示,您可以看到这是默认的CSS,它使交换机的背景为青色。我不能通过使用id来改变它。 我尝试这样做:

.switch label input[type=checkbox]#profile-switch:checked + .lever#profile-switch {
  background-color: #ffffff;
}

但它似乎没有效果。

1 个答案:

答案 0 :(得分:1)

<label>
Off
<input id="profile-switch-input" type="checkbox" checked="">
<span id="profile-switch-lever" class="lever"></span>
On
</label>

CSS

.switch label input#profile-switch-input[type="checkbox"]:checked + #profile-switch-lever.lever::after {
    background-color: #fff;
}

结果

enter image description here

原创

enter image description here

相关问题