我正在为复选框使用 Font-awesome 图标,但在对齐正方形中的图标时遇到问题。它看起来有点难看,而且我尝试了多少填充和对齐,但由于边缘不同,它不能很好地调整(字体很棒的图标有圆边,不适合我的正方形)。有人知道如何将它完美地放入我的广场吗?
有没有办法改变图标的圆边(实际上不必改变字体很棒的源代码?)谢谢。
HTML:
<input type="checkbox" name="checkbox" id="checkbox"class="checkboxClass"/>
<label for="checkbox" class="labelForCheckboxClass"></label>
CSS:
.checkboxClass {
opacity: 0;
}
.labelForCheckboxClass {
position: relative;
font-size: 16px;
cursor: pointer;
padding-left: 20.5px;
padding-top: 0;
padding-bottom: 0;
border: 1px solid gray;
background-color: white;
}
.labelForCheckboxClass:after {
content: '\f14a';
max-width: 0;
overflow: hidden;
opacity: 0.5;
line-height: 20px;
border-radius: 0;
}
.labelForCheckboxClass:before, .labelForCheckboxClass:after {
font-family: FontAwesome;
font-size: 25px;
position: absolute;
top: 0;
left: 0;
}
.checkboxClass:checked ~ label:after {
max-width: 25px;
opacity: 1;
}
这是 JsFiddle.
最佳答案
问题是您试图用具有圆形边框的图形填充方框空间。您不能使用 css 修改复选标记的边框,因为它是字体的形状...您无权使用 css 访问该属性。
一种变通方法是使用带有 border-radius 的正方形,您可能会在这里看到: http://jsfiddle.net/leojavier/0h7gfdq6/1/
.labelForCheckboxClass {
position: relative;
font-size: 16px;
cursor: pointer;
padding-left: 21.5px;
padding-bottom: 2px;
border: 1px solid gray;
background-color: #FFF;
border-radius:4px;
}
另一方面,如果你想保留方框的尖锐方形边缘,你可能想使用勾选图标 (white) 而没有来自 font-awesome 的背景,只需切换背景使用 javascript 点击时将标签颜色设置为(黑色)。
这是一个没有去除尖锐边缘的版本:
关于javascript - Font Awesome 图标对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32618440/