字体很棒,同一个图标有不同的宽度

时间:2016-03-25 14:57:28

标签: html css font-awesome

我对Font Awesome图标有一点问题。

我有2个相同版本的网站(用于开发和测试),图标显示不同,同时具有相同的CSS样式。

我用这个图标描述了这个问题:

Font awesome, same icon with different width



.btnFilter {
    color: #666666;
    padding-top: 4px;
    font-size: 18px;
    text-align: center;
}
.circle {
    border: solid #999 1px;
    border-radius: 13px;
    box-sizing: border-box;
    width: 26px;
    height: 26px;
    text-align: center;
    font-size: 18px;
}

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>

<i class="fa fa-times circle btnFilter"></i>
&#13;
&#13;
&#13;

这个CSS和HTML标记放在开发和测试版本上,chrome dev工具显示相同的样式,并悬停字体 - 真棒图标:在伪元素的大小给出结果之前,如上图所示。

2 个答案:

答案 0 :(得分:1)

我认为它与font-size有关。我认为它是因为font-awesome有一个

的声明
    font: normal normal normal 14px/1 FontAwesome;

因此,删除字体大小或使用em调整字体大小,它应该按预期工作

如果您在字体大小中添加!important,您会看到在您的某个网站上看到的奇怪结果。

&#13;
&#13;
.btnFilter {
    color: #666666;
    padding-top: 4px;
    font-size: 18px !important;
    text-align: center;
}
.circle {
    border: solid #999 1px;
    border-radius: 13px;
    box-sizing: border-box;
    width: 26px;
    height: 26px;
    text-align: center;
    font-size: 18px !important;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>

<i class="fa fa-times circle btnFilter"></i>
&#13;
&#13;
&#13;

或者你可以这样做

&#13;
&#13;
.circle{
    width:18px;
    height:18px;
    padding: 3px;
    background-color:white;
    border-radius:100%;
    line-height:18px;
    text-align:center;
    vertical-align:middle;
    display:inline-block;
    border: solid #999 1px;
}

.btnFilter { 
  line-height: inherit; 
  font-size: 18px;
  color: #666666;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>

<div class="circle">
  <i class="fa fa-times btnFilter"></i>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我认为在这里使用em而不是px值可以提供更好的服务......然后一切都会调整为字体大小。

至于您的具体问题,line-height / font-size在font-awesome和您的特定样式之间存在冲突。

也可能不需要顶部填充。

&#13;
&#13;
html {
  box-sizing: border-box;
}
*,
*::before,
*::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}
.btnFilter {
  color: #666666;
  font-size: 160px !important;
  /* for demo only */
  line-height: 1em;
  text-align: center;
}
.fa::before {
  line-height: inherit;
}
.circle {
  border: solid #999 1px;
  border-radius: 50%;
  width: 1.1em;
  height: 1.1em;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<i class="fa fa-times circle btnFilter"></i>
&#13;
&#13;
&#13;

Codepen Demo

相关问题