如何在 Algolia 即时搜索中将复选框更改为图标?
How to change checkbox to Icon in Algolia Instant Search?
Algolia 即时搜索提供如下复选框和标签:
<label class="ais-RefinementList-label">
<input type="checkbox" class="ais-RefinementList-checkbox" value="Stroke">
<span class="ais-RefinementList-labelText">Stroke</span> <span class="ais-RefinementList-count">986</span>
</label>
我很想用 Font Awesome 图标替换默认复选框。
这样做的唯一方法是基于这个例子:
http://jsfiddle.net/4huzr/
但这里的设置完全不同 <input /><label>
而不是 <label><input /></label>
。
无论如何都能实现吗?
您还需要为跨度添加相同的 css:
input[type=checkbox] {
display: none;
}
input[type=checkbox] + label,
input[type=checkbox] + span
{
display:inline-block;
padding-left: 20px;
position: relative;
}
input[type=checkbox] + label:before,
input[type=checkbox] + span:before
{
content:"";
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0;
position: absolute;
left:0 ;
top: 2px;
}
input[type=checkbox]:checked + label:before,
input[type=checkbox]:checked + span:before
{
content: "\f00c";
font-family: 'FontAwesome';
background: blue;
color:#fff;
font-size: 14px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
This one works with a replacement:<br />
<input type='checkbox' name='thing1' value='valuable' id="thing1"/>
<label for="thing1">Thing 1</label>
<hr />
This one does not:<br />
<label class="ais-RefinementList-label">
<input type="checkbox" class="ais-RefinementList-checkbox" value="Stroke">
<span class="ais-RefinementList-labelText">Thing 2</span>
</label>
Algolia 即时搜索提供如下复选框和标签:
<label class="ais-RefinementList-label">
<input type="checkbox" class="ais-RefinementList-checkbox" value="Stroke">
<span class="ais-RefinementList-labelText">Stroke</span> <span class="ais-RefinementList-count">986</span>
</label>
我很想用 Font Awesome 图标替换默认复选框。 这样做的唯一方法是基于这个例子: http://jsfiddle.net/4huzr/
但这里的设置完全不同 <input /><label>
而不是 <label><input /></label>
。
无论如何都能实现吗?
您还需要为跨度添加相同的 css:
input[type=checkbox] {
display: none;
}
input[type=checkbox] + label,
input[type=checkbox] + span
{
display:inline-block;
padding-left: 20px;
position: relative;
}
input[type=checkbox] + label:before,
input[type=checkbox] + span:before
{
content:"";
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0;
position: absolute;
left:0 ;
top: 2px;
}
input[type=checkbox]:checked + label:before,
input[type=checkbox]:checked + span:before
{
content: "\f00c";
font-family: 'FontAwesome';
background: blue;
color:#fff;
font-size: 14px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
This one works with a replacement:<br />
<input type='checkbox' name='thing1' value='valuable' id="thing1"/>
<label for="thing1">Thing 1</label>
<hr />
This one does not:<br />
<label class="ais-RefinementList-label">
<input type="checkbox" class="ais-RefinementList-checkbox" value="Stroke">
<span class="ais-RefinementList-labelText">Thing 2</span>
</label>