input[type="checkbox"] {
display: none;
}
span:before {
font-family: "FontAwesome";
font-style: normal;
content: 'O';
margin-right: 3px;
font-size: 30px;
}
input[type="checkbox"]:checked ~ span:before {
content: 'Z';
}
<label>
<input type="checkbox"/>
<span>Text</span>
</label>
答案 0 :(得分:4)
您可以在display: flex
元素上使用align-items: center
和span
。
span {
display: flex;
align-items: center;
}
input[type="checkbox"] {
display: none;
}
span:before {
font-family: "FontAwesome";
font-style: normal;
content: 'O';
margin-right: 3px;
font-size: 30px;
}
input[type="checkbox"]:checked ~ span:before {
content: 'Z';
}
<label>
<input type="checkbox" />
<span>Text</span>
</label>
答案 1 :(得分:2)
添加
vertical-align:middle;
到
span:before { font-family: "FontAwesome"; font-style: normal; content: 'O'; margin-right: 3px; font-size: 30px; vertical-align:middle; }
答案 2 :(得分:1)
您可以将以下内容添加到span:before
元素中:
span:before {
vertical-align: middle;
position: relative;
}
答案 3 :(得分:0)
将范围的display
设置为flex
并对齐项center
会有效。
input[type="checkbox"] {
display: none;
}
label span {
display: flex;
align-items: center;
}
span:before {
font-family: "FontAwesome";
font-style: normal;
content: 'O';
margin-right: 3px;
font-size: 30px;
}
input[type="checkbox"]:checked ~ span:before {
content: 'Z';
}
<label>
<input type="checkbox"/>
<span>Text</span>
</label>
答案 4 :(得分:0)
只需将vertical-align:sub添加到span:before
这是js小提琴链接 - Fiddle
span:before {
font-family: "FontAwesome";
font-style: normal;
content: 'O';
margin-right: 3px;
font-size: 30px;
vertical-align:sub;
}