我有一个自定义样式的复选框,请参阅此JSFiddle:
https://jsfiddle.net/y58zrd4m/
我的HTML看起来像这样:
<label class="checkbox">
<input type="checkbox" />
<span>Lorem ipsum</span>
</label>
现在我希望我的文本相对于复选框垂直居中,我该如何实现?
答案 0 :(得分:2)
CSS 中的某些更改将帮助您实现以下目标:
.checkbox {
cursor: pointer;
position: relative;
}
.checkbox input[type="checkbox"] {
display: none;
}
.checkbox span {
font-size: 20px;
display: inline-block;
padding: 10px 0 0 40px;
}
.checkbox span:before {
content: "";
display: inline-block;
width: 25px;
height: 25px;
border: 2px solid rgba(0, 0, 0, 0.5);
border-radius: 5px;
margin: 0;
position: absolute;
left: 2px;
top: -7px;
}
.checkbox span:after {
content: "";
display: none;
position: absolute;
left: 12px;
top: -2px;
width: 5px;
height: 13px;
border-bottom: 4px solid white;
border-right: 4px solid white;
border-radius: 1px;
transform: rotate(30deg);
}
.checkbox input[type="checkbox"]:checked + span:before {
border-color: #03a9f4;
background-color: #03a9f4;
}
.checkbox input[type="checkbox"]:checked + span:after {
display: inline-block;
}
&#13;
<label class="checkbox">
<input type="checkbox" />
<span>Lorem ipsum</span>
</label>
&#13;