Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set checkbox color for chrome

In my application I am showing a graph with legends. Legends have colored checkboxes. Below is code for a checkbox that works fine in IE but the color does not appear in Chrome and Firefox

<input type="checkbox" style="background-color:#d65aef;">

Please tell me what should I do so that it works in IE,Chrome and Firefox. I have to use the hex color as used in the given code.

like image 348
agarwal_achhnera Avatar asked Jan 23 '14 07:01

agarwal_achhnera


2 Answers

Form controls like checkbox, radio, select and etc using a platform-native styling based on the operating system's theme. You can reset it by using -moz-appearance and -webkit-appearance properties. But this properties will also reset sizes of control and may be something else, so you will need to add width/height manually:

input[type=checkbox] {
     background: red;
    -webkit-appearance: none;
    -moz-appearance: none;
    height: 16px;
    width: 16px;
}

Also for checkbox you need to provide a checked state render:

input[type=checkbox]:checked {
     background-image: url(/*custom checked icon url*/);
}
like image 73
Pinal Avatar answered Sep 21 '22 08:09

Pinal


Close input into span (or div) and set span color.

<span style="background-color:#d65aef;"><input type="checkbox" class="base" name="w3wp" style="background-color:#d65aef;" value="w3wp" checked="" onclick="legendChanged();" alt="fd" title="w3wp"></span>
like image 36
marioosh Avatar answered Sep 21 '22 08:09

marioosh