Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the color of checkbox if checked [duplicate]

I am trying to change the background color and border of a checkbox but it is not working.

HTML:

<label for="checkbox1" class="checkbox">
  <input id="checkbox1" type="checkbox" role="checkbox" /><span class="custom">Checkbox</span>
</label>

CSS:

.checkbox input:checked {
    border-color: red;
    background-color:red;
}

JSFiddle Demo

UPDATE:

I can't change the markup

like image 326
user4756836 Avatar asked Aug 31 '16 15:08

user4756836


People also ask

How can I change the color of a checkbox?

To style the checkbox the user first needs to hide the default checkbox which can be done by setting the value of the visibility property to hidden. Example 1: Consider the example where HTML checkbox is styled using CSS. When the user clicks the checkbox, the background color is set to green.

How do I change the color of a checkbox when using css?

Use the accent-color property to change the checkbox color in CSS.

How do I change the color of a checkmark in HTML?

To change the color of the checkmark, change the border color on the ::after style. Additionally, if you wanted it to always match your text color remove the border color on it altogether. To change the radio, change the radial gradient start color (the one that isn't white).


2 Answers

Use below option

input[type="checkbox"]#checkbox1:checked + span {
      border-color: red;
    background-color:red;
}
like image 172
Naga Sai A Avatar answered Sep 28 '22 07:09

Naga Sai A


You will have to wrap the checkbox in a span to do it. Found a Fiddle with Ex.

<span class="bigcheck">
    <label class="bigcheck">Cheese
        <input type="checkbox" class="bigcheck" name="cheese" value="yes"/>
        <span class="bigcheck-target"></span>
    </label>
</span>

Hope it helps :)

like image 24
theLearner Avatar answered Sep 28 '22 07:09

theLearner