Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change checkbox background color

I gave checkboxes to the classes of my checkboxes and when the checkbox is checked in css, the background color is normally blue, but I want to make it red for example, how do I do that?

 <div class="container-food">
                    <div class="card">
                        <input id="red" class="checkbox" type="checkbox">
                        <p class="count">1 and 1/2 cups (150g) <b>graham cracker crumbs</b> (about 10 full sheet
                            grahamcrackers) </p>
                    </div>
                    <div class="card">
                        <input class="checkbox" type="checkbox">
                        <p class="count">5 Tablespoons (70g) <b>unsalted butter</b>, melted</p>
                    </div>
                    <div class="card">
                        <input class="checkbox" type="checkbox">
                        <p class="count">1/4 cup (50g) <b>granulated sugar</b></p>
                    </div>
                </div>

css;

.checkbox:checked {
background-color: red; /*not worked*/
height: 10px; /*worked*/

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

to check if the problem is in the selectors

.checkbox:checked{

height:10px;

}

I tried your code and it worked. This way, I realized that the problem is not in the selectors. but background-color:red; it didn’t work when i gave it.

>Solution :

Try this:

.checkbox:checked {
accent-color: red;
}

It’ll fix your problem.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading