Changing color of checkbox label when checked

11,129

You should place .onlinecheckbox after input[type="checkbox"]:

input[type="checkbox"].onlinecheckbox + label {
    color: #ffffff;
}

input[type="checkbox"].onlinecheckbox:checked + label {
    color: #428bca;
}
Share:
11,129
user2694306
Author by

user2694306

Updated on June 04, 2022

Comments

  • user2694306
    user2694306 almost 2 years

    I am trying to change the color of my checkbox's label when it is checked. I've done this before on other sites, but for some reason my code just isn't working on this one. I am using Drupal 7 with bootstrap 3+.

    My checkbox looks like this:

    <div class="checkbox">
        <input class="onlinecheckbox" type="checkbox" name="dealtype[]" id="prov1" onchange="this.form.submit()" value="booking" checked="">
        <label for="prov1">Booking</label>
    </div>
    

    My css is as follows:

    .onlinecheckbox input[type="checkbox"] + label {
        color: #ffffff;
    }
    
    .onlinecheckbox input[type="checkbox"]:checked + label {
        color: #428bca;
    }