简体   繁体   English

如何更改禁用复选框上复选标记的颜色

[英]How to change the color on checkmark on disabled checkbox

Here is example of my CSS:这是我的 CSS 的示例:

.checkbox { 

input[type='checkbox'] {
&+label{
&:after {
content: '';
border: 2px solid white
}}

&:disabled{
&+label{
&+:before{
opacity: .7;
}}
}}
}

So the border: 2px solid white;所以border: 2px solid white; is changing the color of the checkmark.正在更改复选标记的颜色。 But in both situations, when checkbox is disabled and enabled.但在这两种情况下,当复选框被禁用和启用时。

I need to change the color of the ckeckmark in black only if its disabled.只有当它被禁用时,我才需要将它的颜色更改为黑色。

If i try to change here &:disabled{...} It is changing the color only on the border and not on the checkmark.如果我尝试在这里更改&:disabled{...}它只会在边框上更改颜色,而不是在复选标记上。

Does someone know how to change the color on checkmark in disabled checkbox?有人知道如何更改禁用复选框中复选标记的颜色吗?

Checkboxes are inherently annoying.复选框本身就很烦人。 There isn't an easy way to change checkboxes.没有简单的方法来更改复选框。 Here I'll provide a custom checkbox that is easily changeable.在这里,我将提供一个易于更改的自定义复选框。

 * { margin: 0; padding: 0; --main-color: #1589FF; }.checkbox__group { display: inline-flex; align-content: center; justify-content: center; align-items: center; user-select: none; font-size: 20px; margin-bottom: 10px; }.checkbox__group:hover { cursor: pointer; }.checkbox__original { display: none; }.checkbox__custom { width: 1.5em; height: 1.5em; border-radius: 4px; border: .1em solid #ccc; text-align: center; color: white; transition: background.2s, border-color.2s; display: flex; justify-content: center; align-items: center; user-select: none; margin-right: .5em; flex-shrink: 0; content: ''; user-select: none; }.checkbox__custom::after { content: '\2714'; transform: scale(0); transform: rotate(0deg); transition: transform.2s; }.checkbox__group:focus { outline: none; }.checkbox__group:focus.checkbox__custom{ border: .1em solid var(--main-color); outline: none; }.checkbox__original:checked +.checkbox__custom { background: var(--main-color); border: .1em solid var(--main-color); }.checkbox__original:checked +.checkbox__custom::after { transform: scale(1); transform: rotate(360deg); }
 <label for="checkbox" id="checkbox__group" class="checkbox__group"> <input type="checkbox" id="checkbox" name="checkbox" class="checkbox__original"> <div class="checkbox__custom"></div> Hello! </label>

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

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