如何更改 javascript ag 网格中禁用的复选框背景颜色?

How can I change disabled checkbox background color in javascript ag grid?

我已经尝试了我能找到的任何东西,基本上一般的想法是使用以下 css 规则:

input[type=checkbox][disabled] {
    background: red !important;
    background-color: red !important;
    outline: 1px solid red;
}

问题是唯一有效的规则是大纲。背景不会以任何方式改变。它仍然是灰色的。我提供了上面发布的 css 规则结果的屏幕截图。

是否有任何有效的方法可以成功更改禁用复选框的背景颜色?

无法使用原生外观,因此您必须使用 label 创建自定义模板并使用伪元素,如 :before:after:

.flex-container {
  display: flex;
  flex-flow: row-wrap;
}

.flex-column {
  padding: 0 15px;
  flex: 0 0 auto;
}

[type="checkbox"]:checked,
[type="checkbox"]:not(:checked) {
    position: absolute;
    left: -9999px;
}
[type="checkbox"]:checked + label,
[type="checkbox"]:not(:checked) + label
{
    position: relative;
    padding-left: 28px;
    cursor: pointer;
    line-height: 20px;
    display: inline-block;
    color: #666;
}
[type="checkbox"]:checked + label:before,
[type="checkbox"]:not(:checked) + label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 18px;
    height: 18px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 5px;
}
[type="checkbox"]:checked + label:after,
[type="checkbox"]:not(:checked) + label:after {
    content: '';
    width: 8px;
    height: 8px;
    background: #00579c;
    position: absolute;
    top: 6px;
    left: 6px;
    border-radius: 50%;
    -webkit-transition: all 0.2s ease;
    transition: all 0.2s ease;
}
[type="checkbox"]:not(:checked) + label:after {
    -webkit-transform: scale(0);
    transform: scale(0);
}
[type="checkbox"]:checked + label:after {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
}

[type="checkbox"]:disabled + label {
    opacity: 0.7;
    cursor: not-allowed;
}

[type="checkbox"]:disabled + label:before {
    border-color: red;
}
 <div class="flex-container">
   <div class="flex-column">
    <input type="checkbox" id="test2">
    <label for="test2">Default</label>
  </div>
  
  <div class="flex-column">
    <input type="checkbox" id="test1" checked>
    <label for="test1">Checked</label>
  </div>
  
   <div class="flex-column">
    <input type="checkbox" id="test3" disabled>
    <label for="test3">Disabled</label>
  </div>
 </div>