Maison  >  Questions et réponses  >  le corps du texte

Comment appliquer 2 couleurs différentes à la case à cocher en CSS ?

J'utilise des cases à cocher sur mes pages. bons résultats. Cependant, je veux une case à cocher bleu clair et une autre case à cocher jaune clair. Les deux cases sont actuellement bleu clair. Comment puis-je transformer l’autre en jaune clair ?

C'est ce que j'ai.

input[type=checkbox] {
  position: relative;
  cursor: pointer;
margin-right: 10px;
}
input[type=checkbox]:before {
  content: "";
  display: block;
  position: absolute;
  width: 16px;
  height: 16px;
  top: 0;
  left: 0;
  border: 1px solid #99AFC1;
  border-radius: 3px;
  background-color: lightblue;
  padding: 1px;
}
input[type=checkbox]:checked::before {
  background-color: lightblue;
}

input[type=checkbox]:checked::after {
  content: "";
  display: block;
  width: 5px;
  height: 10px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
  position: absolute;
  top: 2px;
  left: 6px;
}
<p><label><input type="checkbox" class="filter" value="Test1">Test1</label> <label><input type="checkbox" class="filter" value="Test2">Test2</label></p>

P粉949190972P粉949190972203 Il y a quelques jours404

répondre à tous(1)je répondrai

  • P粉539055526

    P粉5390555262024-03-30 07:16:06

    *Cela fonctionne de la même manière dans Chrome, Edge et Firefox.

    Commandez simplement ce que vous voulez浅黄色提供一个.
    Pour l'approche multi-navigateurs, j'ai utilisé pour le style.

    label.checkbox input[type="checkbox"] {
      display:none;
    }
    label.checkbox span {
      display:inline-block;
      border: 1px solid Gray;
      border-radius: 4px;
      width: 18px;
      height: 18px;
      background-color: lightblue;
      vertical-align: top;
      position: relative;
    }
    label.checkbox :checked + span {
      width: 18px;
      height: 18px;
    }
    label.checkbox :checked + span:after {
      content: '14';
      font-size: 100%;
      position: absolute;
      top: -12%;
      left: 12%;
      color: lightyellow;
    }
    
    /* Make the above your default checkbox, and the below can be used for special ones. */
    
    label.checkbox.difcol span {
      background-color: lightyellow; /* New Box Color */
    }
    label.checkbox.difcol :checked + span:after {
      color: lightblue; /* Corresponding New Checkmark Color */
    }
    <p>
    <label class="checkbox"><input type="checkbox"/><span></span></label> Test1
    <label class="checkbox difcol"><input type="checkbox"/><span></span></label> Test2
    </p>

    répondre
    0
  • Annulerrépondre