简体   繁体   English

在 Materialise 框架中更改复选框的颜色

[英]Change color of checkbox in Materialize framework

I am currently working with Materialize framework and wondering is it possible to change the colour of the filled-in checkbox as it is green on default.我目前正在使用 Materialize 框架,想知道是否可以更改填充复选框的颜色,因为它默认为绿色。

<input type="checkbox" class="filled-in" id="filled-in-box" checked="checked" />
<label for="filled-in-box">Filled in</label>

Any ideas would be appreciated.任何想法,将不胜感激。 Thanks谢谢

Add a class to the checkbox input which will style the after pseudo-element of the label向复选框输入添加一个类,该类将为标签的后伪元素设置样式

 .checkbox-orange[type="checkbox"].filled-in:checked + label:after{ border: 2px solid #ff9800; background-color: #ff9800; }
 <input type="checkbox" class="filled-in checkbox-orange" id="filled-in-box" checked="checked" /> <label for="filled-in-box"></label>

With Materialize version 1.0.0 the language markup differs from that given above.在 Materialise 版本 1.0.0 中,语言标记与上面给出的不同。 The markup and the CSS to change the colour (in my case to blue-grey) of the filled-in checkbox now looks like this:用于更改已填充复选框颜色(在我的情况下为蓝灰色)的标记和 CSS 现在如下所示:

 /* change colour of filled in check box */ .checkbox-blue-grey[type="checkbox"].filled-in:checked+span:not(.lever):after { border: 2px solid #607d8b; background-color: #607d8b; }
 <link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet"/> <p> <label> <input type="checkbox" class="filled-in checkbox-blue-grey" checked="checked" /> <span>Filled in</span> </label> </p>

This depends on the type of checkbox you use - filled-in class or without.这取决于您使用的复选框类型 - 填充类或不填充类。 You'll have to put in the CSS color keyword as needbe... just replace my 'indigo' for whatever color you require.您必须根据需要输入 CSS 颜色关键字...只需将我的“靛蓝”替换为您需要的任何颜色。

*** Note - Ligthen and Darken classes will not work with this. *** 注意 - Ligthen 和 Darken 类不适用于此。

.checkbox-indigo[type="checkbox"] + label:before{
    border: 2px solid indigo;
    background: transparent;
}
.checkbox-indigo[type="checkbox"]:checked + label:before{
    border: 2px solid transparent;
    border-bottom: 2px solid indigo;
    border-right: 2px solid indigo;
    background: transparent;
}
.checkbox-indigo.filled-in[type="checkbox"] + label:after{
    border: 2px solid indigo;
    background: transparent;
}
.checkbox-indigo.filled-in[type="checkbox"]:checked + label:after{
    background: indigo;
}
.checkbox-indigo.filled-in[type="checkbox"]:checked + label:before{
    border-top: 2px solid transparent;
    border-left: 2px solid transparent;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
}

http://embed.plnkr.co/zWaJVtsAVXxs0fVLmxRH/ http://embed.plnkr.co/zWaJVtsAVXxs0fVLmxRH/

如果要更改复选框的所有颜色:

input[type="checkbox"]:checked + span:not(.lever)::before{border:2px solid transparent;border-bottom:2px solid #006AB5;border-right:2px solid #006AB5;background:transparent;}

Sorry that I am late but I too faced the same problem recently so I am sharing how I fixed it (at least in my case)对不起,我迟到了,但我最近也遇到了同样的问题,所以我分享了我是如何解决它的(至少在我的情况下)

When I was facing this problem, I looked up in almost all sites and forums but I didn't get a working solution that satisfied me.当我遇到这个问题时,我在几乎所有的网站和论坛中都进行了查找,但没有得到让我满意的有效解决方案。 hence I went to the official css library https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css and changed the core values according to my needs.因此我去了官方的 css 库https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css并根据我的需要更改了核心值。

For the checkbox tick mark, I need to change the color in two cases:对于复选框刻度线,我需要在两种情况下更改颜色:

First is when the user check the box by mouse click, second is when the user press tab and pressing spacebar for checking the box.第一种是用户通过鼠标单击选中复选框,第二种是用户按 Tab 并按空格键选中复选框。

So the following change might work for you:因此,以下更改可能对您有用:

[type="checkbox"].filled-in:checked+span:not(.lever):before{
    border-right:2px solid cyan;
    border-bottom:2px solid cyan;
}

[type="checkbox"].filled-in:checked+span:not(.lever):after{
    border:2px solid black;
    background-color:black;
}

[type="checkbox"].filled-in.tabbed:checked:focus+span:not(.lever):after{
    background-color:black;
    border-color:black;
} 

If you want the full code visit https://codepen.io/MrSrv7/pen/RwaNeyd如果您想要完整代码,请访问https://codepen.io/MrSrv7/pen/RwaNeyd

I have created a simple login form with HTML CSS and JS,我用 HTML CSS 和 JS 创建了一个简单的登录表单,

Demo/Preview here: https://mrsrv7.github.io/LoginForm/演示/预览: https ://mrsrv7.github.io/LoginForm/

Repository here: https://github.com/MrSrv7/LoginForm/存储库在这里: https ://github.com/MrSrv7/LoginForm/

CSS code CSS 代码

.custom_checkbox[type="checkbox"]:checked + span:not(.lever)::before {
  border: 2px solid transparent;
  border-bottom: 2px solid #ffd600;
  border-right: 2px solid #ffd600;
  background: transparent;
}

HTML code HTML 代码

<label>
    <input type="checkbox" class="custom_checkbox" />
    <span>Text</span>
</label>

Demo演示

JSFiddle demo JSFiddle 演示

I wanted to change the background color of a materialize checkbox.我想更改物化复选框的背景颜色。

This is how i did it after following the tips above.这就是我在遵循上述提示后所做的。 CSS Code: CSS 代码:

.checkbox[type="checkbox"]:checked + span:not(.checkbox)::after {
    border: 2px solid transparent;
    background-color: var(--color-primary);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM