简体   繁体   English

真棒字体图标对齐

[英]Font-awesome icon alignment

I'm using Font-awesome icon for a checkbox, but having problem aligning the icon in the square. 我正在使用“超棒字体”图标作为复选框,但是在方形图标对齐时遇到问题。 It kind of looks ugly and how much I try to work with the padding and alignment, it does not adjust well as the edges are different(the font-awesome icon has round edges which does not fit well with my square). 它看起来很丑陋,并且我尝试使用多少填充和对齐方式,但由于边缘不同而无法很好地进行调整(字体真棒图标的圆形边缘与我的正方形不太吻合)。 Any one has any ideas of how to fit it perfectly in my square? 有人对如何完美地融入我的广场有任何想法吗?

Is there a way to change the round edges of the icon (without actually having to make changes to the font-awesome source code?) Thank you. 有没有办法改变图标的​​圆角边缘(实际上不必更改字体真棒的源代码?)谢谢。

HTML: HTML:

<input type="checkbox" name="checkbox" id="checkbox"class="checkboxClass"/>    
<label for="checkbox" class="labelForCheckboxClass"></label> 

CSS: 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; 
}

Here is the JsFiddle. 这是JsFiddle。

EDIT: 编辑:

For square corners try this: 对于方角,请尝试以下操作:

.checkboxClass {   
    opacity: 0;
}

.labelForCheckboxClass {
    position: relative;
    font-size: 16px;
    cursor: pointer;
    padding-left: 17px;
    padding-top: 0;
    padding-bottom: 0;
    border: 1px solid gray;
    background-color: white;   
}

.labelForCheckboxClass:after {
    content: '\f00c';
    color:white;
    background-color: black;
    max-width: 0;
}

.labelForCheckboxClass:before, .labelForCheckboxClass:after {
    font-family: FontAwesome;
    font-size: 17px;
    position: absolute;
    top: 0;
    left: 0;
    height:1.05em;
}

.checkboxClass:checked ~ label:after {
    max-width: 17px; 
    opacity: 1; 
}

Try with this: 试试这个:

.labelForCheckboxClass {
    position: relative;
    font-size: 18px;
    cursor: pointer;
    padding-left: 21.5px;
    padding-top: 0;
    padding-bottom: 0;
    border: 1px solid gray;
    background-color: white;
    border-radius: 4px;
}

the problem is that you are trying to fill a square box space with a graphic that has rounded borders. 问题是您试图用带有圆角边框的图形填充方盒空间。 You can't modify the border of the checkmark with css because is the shape of the font... You don't have access to that property with css. 您不能使用css修改选中标记的边框,因为它是字体的形状...您无法使用css来访问该属性。

one work around would be to have the square with border-radius I you may see here: http://jsfiddle.net/leojavier/0h7gfdq6/1/ 一种解决方法是使边框与半径成正方形,您可能会在这里看到: 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;
}

In the other hand if you want to keep the sharp square edges of the box, you may want to use the checkmark icon (white) without the background from font-awesome and just toggle the background color of your label to (black) on click with javascript. 另一方面,如果要保留方框的尖锐方形边缘,则可能需要使用选中标记图标(白色),而背景的字体却不那么棒,只需单击即可将标签的背景色切换为(黑色)使用javascript。

Here is a version without removing the sharp edges: 这是一个不消除尖锐边缘的版本:

http://jsfiddle.net/leojavier/0h7gfdq6/3/ http://jsfiddle.net/leojavier/0h7gfdq6/3/

Well also adding right: 0 and bottom: 0 to .labelForCheckboxClass:before, .labelForCheckboxClass:after helps to an extent. 还要在.labelForCheckboxClass:before, .labelForCheckboxClass:after right: 0添加right: 0right: 0 bottom: 0

Here's your updated fiddle: http://jsfiddle.net/4zjtp/134/ 这是您更新的小提琴: http : //jsfiddle.net/4zjtp/134/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM