如何更改复选框的背景色? [英] how to change the background color of checkbox?
本文介绍了如何更改复选框的背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CSS:
#partoption2 {
background: none repeat scroll 0 0 #FF0000;
height: 16px;
position: relative;
top: 3px;
width: 16px;
}
HTML:
<input type="checkbox" name="parttwo" id="partoption2" value="206365-KT:" >manoji
您好,我在这里的朋友需要复选框的背景颜色为绿色,而在我选中时,取消选中时它应该变为红色.谁能给我解决方案?
Hi Friends here I need background color of the checkbox to be green and while I check it should go red when I uncheck. Can anyone give me a solution?
http://jsfiddle.net/5txp5g5u/1/
推荐答案
http://codepen.io /dcdev/full/toBzb/
未选中时为绿色,选中时为红色..这是通过实际上隐藏默认复选框并将样式设置为隐藏的复选框的外观看起来像一个复选框来实现的.
Green when unchecked, red when checked.. This works by actually hiding the default checkbox and styling the label over to of the hidden checkbox to look like a checkbox.
label {
position: absolute;
width: 20px;
height: 20px;
background-color: green;
-webkit-transition: background-color 1s ease-out 1s;
-moz-transition: background-color 1s ease-out 1s;
-o-transition: background-color 1s ease-out 1s;
transition: background-color 1s ease-out 1s;
}
.checkbox_red input[type=checkbox]:checked + label {
background-color:red;
-webkit-transition: background-color 1s ease-out 1s;
-moz-transition: background-color 1s ease-out 1s;
-o-transition: background-color 1s ease-out 1s;
transition: background-color 1s ease-out 1s;
}
.checkbox_red label:after {
position: absolute;
bottom: 8px;
width: 18px;
height: 10px;
opacity: 0;
content: '';
background: transparent;
border: 3px solid #000;
border-top: none;
border-right: none;
-webkit-transform: rotate(-50deg);
-moz-transform: rotate(-50deg);
-ms-transform: rotate(-50deg);
-o-transform: rotate(-50deg);
transform: rotate(-50deg);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
.checkbox_red input[type=checkbox] {
visibility: hidden;
}
.checkbox_red input[type=checkbox]:checked + label:after {
opacity: 1;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
}
和html
<div class="checkbox_red">
<input type="checkbox" value="none" id="checkbox_red1" name="check">
<label for="checkbox_red1"></label>
</div>
这篇关于如何更改复选框的背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文