The heading pretty much explains it. I have a couple of checkboxes inside a scrollable div. But for some reasons the 'background-color' attribute doesn't work. Although the 'margin-top' does seem to work...
Just puzzling me how one attribute can work and another not. It's also not like the div has it's own set of background color attributes that could potentially over ride the checkboxes attributes.
Anyways, below is my HTML (which is generated by JSP):
<div class="listContainer">
<input type="checkbox" class="oddRow">item1<br/>
<input type="checkbox" class="evenRow">item2<br/>
<input type="checkbox" class="oddRow">item3<br/>
<input type="checkbox" class="evenRow">item4<br/>
...
</div>
And here is my CSS:
.listContainer {
border:2px solid #ccc;
width:340px;
height: 225px;
overflow-y: scroll;
margin-top: 20px;
padding-left: 10px;
}
.oddRow {
margin-top: 5px;
background-color: #ffffff;
}
.evenRow{
margin-top: 5px;
background-color: #9FFF9D;
}
Thanks in advance for anyone that can point me in the right direction!
This question is related to
html
css
checkbox
background-color
Initially posted here.
input[type="checkbox"] {_x000D_
cursor: pointer;_x000D_
-webkit-appearance: none;_x000D_
-moz-appearance: none;_x000D_
appearance: none;_x000D_
outline: 0;_x000D_
background: lightgray;_x000D_
height: 16px;_x000D_
width: 16px;_x000D_
border: 1px solid white;_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:checked {_x000D_
background: #2aa1c0;_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:hover {_x000D_
filter: brightness(90%);_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:disabled {_x000D_
background: #e6e6e6;_x000D_
opacity: 0.6;_x000D_
pointer-events: none;_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:after {_x000D_
content: '';_x000D_
position: relative;_x000D_
left: 40%;_x000D_
top: 20%;_x000D_
width: 15%;_x000D_
height: 40%;_x000D_
border: solid #fff;_x000D_
border-width: 0 2px 2px 0;_x000D_
transform: rotate(45deg);_x000D_
display: none;_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:checked:after {_x000D_
display: block;_x000D_
}_x000D_
_x000D_
input[type="checkbox"]:disabled:after {_x000D_
border-color: #7b7b7b;_x000D_
}
_x000D_
<input type="checkbox"><br>_x000D_
<input type="checkbox" checked><br>_x000D_
<input type="checkbox" disabled><br>_x000D_
<input type="checkbox" disabled checked><br>
_x000D_
You can use peseudo elements like this:
input[type=checkbox] {_x000D_
width: 30px;_x000D_
height: 30px;_x000D_
margin-right: 8px;_x000D_
cursor: pointer;_x000D_
font-size: 27px;_x000D_
}_x000D_
_x000D_
input[type=checkbox]:after {_x000D_
content: " ";_x000D_
background-color: #9FFF9D;_x000D_
display: inline-block;_x000D_
visibility: visible;_x000D_
}_x000D_
_x000D_
input[type=checkbox]:checked:after {_x000D_
content: "\2714";_x000D_
}
_x000D_
<label>Checkbox label_x000D_
<input type="checkbox">_x000D_
</label>
_x000D_
The Best solution to change background checkbox color
input[type=checkbox] {_x000D_
margin-right: 5px;_x000D_
cursor: pointer;_x000D_
font-size: 14px;_x000D_
width: 15px;_x000D_
height: 12px;_x000D_
position: relative;_x000D_
}_x000D_
_x000D_
input[type=checkbox]:after {_x000D_
position: absolute;_x000D_
width: 10px;_x000D_
height: 15px;_x000D_
top: 0;_x000D_
content: " ";_x000D_
background-color: #ff0000;_x000D_
color: #fff;_x000D_
display: inline-block;_x000D_
visibility: visible;_x000D_
padding: 0px 3px;_x000D_
border-radius: 3px;_x000D_
}_x000D_
_x000D_
input[type=checkbox]:checked:after {_x000D_
content: "?";_x000D_
font-size: 12px;_x000D_
}
_x000D_
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>_x000D_
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>_x000D_
_x000D_
<input type="checkbox" name="vehicle" value="Car" checked> I have a bus<br>
_x000D_
We can provide background color from the css file. Try this one,
<!DOCTYPE html>
<html>
<head>
<style>
input[type="checkbox"] {
width: 25px;
height: 25px;
background: gray;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
outline: none;
position: relative;
left: -5px;
top: -5px;
cursor: pointer;
}
input[type="checkbox"]:checked {
background: blue;
}
.checkbox-container {
position: absolute;
display: inline-block;
margin: 20px;
width: 25px;
height: 25px;
overflow: hidden;
}
</style>
</head>
<body>
<div class="checkbox-container">
<input type="checkbox" />
</div>
</body>
</html>
In addition to the currently accepted answer: You can set border and background of a checkbox/radiobutton, but how it is rendered in the end depends on the browser. For example, if you set a red background on a checkbox
This German language article compares a few browsers and explains at least the IE behavior. It maybe bit older (still including Netscape), but when you test around you'll notice that not much has changed. Another comparison can be found here.
When you input the body tag, press space just one time without closing the tag and input bgcolor="red"
, just for instance. Then choose a diff color for your font.
Improving another answer here
input[type=checkbox] {
cursor: pointer;
margin-right: 10px;
}
input[type=checkbox]:after {
content: " ";
background-color: lightgray;
display: inline-block;
position: relative;
top: -4px;
width: 24px;
height: 24px;
margin-right: 10px;
}
input[type=checkbox]:checked:after {
content: "\00a0\2714";
}
After so much trouble i got it.
.purple_checkbox:after {
content: " ";
background-color: #5C2799;
display: inline-block;
visibility: visible;
}
.purple_checkbox:checked:after {
content: "\2714";
box-shadow: 0px 2px 4px rgba(155, 155, 155, 0.15);
border-radius: 3px;
height: 12px;
display: block;
width: 12px;
text-align: center;
font-size: 9px;
color: white;
}
Source: Stackoverflow.com