我正在制作一个带有 font Awesome 和 css 的自定义复选框。
单击/选中复选框时,我尝试在黑色复选框周围创建一些填充(选中/单击时在白色框中有一个较小的黑色框)
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
/*** basic styles ***/
/*** custom checkboxes ***/
input[type=checkbox] {
display: none;
}
/* to hide the checkbox itself */
input[type=checkbox] + label:before {
font-family: FontAwesome;
}
input[type=checkbox] + label:before {
content: "\f096";
}
/* unchecked icon */
/*input[type=checkbox] + label:before { letter-spacing: 10px; }*/
/* space between checkbox and label */
input[type=checkbox]:checked + label:before {
content: "\f0c8";
}
/* checked icon */
input[type=checkbox]:checked + label:before {
letter-spacing: 5px;
}
/* allow space for check mark */
<div>
<input id="box1" type="checkbox" />
<label for="box1"></label>
<br>
<input id="box2" type="checkbox" />
<label for="box2"></label>
<br>
<input id="box3" type="checkbox" />
<label for="box3"></label>
</div>
您使用的是单个字符,因此无法添加字母间距。
我建议这样的事情。
减小替换图标/字符的大小,添加填充和边框。或者,搜索按照您想要的方式显示的正确图标/字符并使用它。
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
/*** basic styles ***/
/*** custom checkboxes ***/
input[type=checkbox] {
display: none;
}
/* to hide the checkbox itself */
input[type=checkbox] + label:before {
font-family: FontAwesome;
}
input[type=checkbox] + label:before {
content: "\f096";
}
/* unchecked icon */
/*input[type=checkbox] + label:before { letter-spacing: 10px; }*/
/* space between checkbox and label */
input[type=checkbox]:checked + label:before {
content: "\f0c8";
display: inline-block;
}
/* checked icon */
input[type=checkbox]:checked + label:before {
font-size: 60%;
border: 1px solid black;
vertical-align: top;
padding: 2px;
border-radius: 2px;
}
/* allow space for check mark */
<div>
<input id="box1" type="checkbox" />
<label for="box1"></label>
<br>
<input id="box2" type="checkbox" />
<label for="box2"></label>
<br>
<input id="box3" type="checkbox" />
<label for="box3"></label>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)