我是CSS和jQuery的新手。我试图自定义该复选框,但没有工作。请你调试一下这个。
这是我的代码:
.checkbox-custom{
opacity: 0;
position: absolute;
}
.checkbox-custom, .checkbox-custom-label{
display: inline-block;
vertical-align: middle;
margin: 5px;
cursor: pointer;
}
.checkbox-custom-label {
position: relative;
}
.checkbox-custom + .checkbox-custom-label:before{
content: '';
background: #fff;
border: 2px solid #ddd;
display: inline-block;
vertical-align: middle;
width: 20px;
height: 20px;
padding: 2px;
margin-right: 10px;
text-align: center;
}
.checkbox-custom:checked + .checkbox-custom-label:before {
content: "\f095";
font-family: 'FontAwesome';
background: rebeccapurple;
color: #fff;
}<input id="checkbox-3" class="checkbox-custom" name="checkbox-3" type="checkbox">
<label for="checkbox-3"class="checkbox-custom-label">Third Choice</label>
我的输出就像,
http://i.stack.imgur.com/PcSYs.png
有人能帮我调试一下吗。
发布于 2016-01-10 06:15:30
您的复选框中有一个矩形,而不是图标,原因是您使用的字体Awesome没有加载它。您的浏览器看到了特殊的U+F095字符,但是它不知道在哪里找到图标,所以它画了一个框。
在有几种加载字体的方法中,最简单的方法是将这一行代码添加到站点的<head>标记中:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">下面是您的代码片段的一个版本,并添加了一行:
.checkbox-custom{
opacity: 0;
position: absolute;
}
.checkbox-custom, .checkbox-custom-label{
display: inline-block;
vertical-align: middle;
margin: 5px;
cursor: pointer;
}
.checkbox-custom-label {
position: relative;
}
.checkbox-custom + .checkbox-custom-label:before{
content: '';
background: #fff;
border: 2px solid #ddd;
display: inline-block;
vertical-align: middle;
width: 20px;
height: 20px;
padding: 2px;
margin-right: 10px;
text-align: center;
}
.checkbox-custom:checked + .checkbox-custom-label:before {
content: "\f095";
font-family: 'FontAwesome';
background: rebeccapurple;
color: #fff;
}<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<input id="checkbox-3" class="checkbox-custom" name="checkbox-3" type="checkbox">
<label for="checkbox-3"class="checkbox-custom-label">Third Choice</label>
https://stackoverflow.com/questions/34702574
复制相似问题