【问题标题】:Font awesome, same icon with different width字体真棒,不同宽度的相同图标
【发布时间】:2016-03-25 23:38:05
【问题描述】:

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

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

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

.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>

此 CSS 和 HTML 标记放置在开发版和测试版上,chrome 开发工具显示相同的样式,并且悬停的 font-awesome 图标 :before 伪元素的大小给出如上图所示的结果。

【问题讨论】:

    标签: html css font-awesome


    【解决方案1】:

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

    关于你的具体问题,line-height/font-size in font-awesome 和你的具体样式有冲突。

    顶部的填充也可能不是必需的。

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

    Codepen Demo

    【讨论】:

      【解决方案2】:

      我相信这与字体大小有关。我认为这是因为 font-awesome 有一个声明

          font: normal normal normal 14px/1 FontAwesome;
      

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

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

      .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;
      }
      <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>

      或者你可以这样做

      .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;
      }
      <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>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-11
        • 2019-02-28
        • 2013-07-01
        • 2016-06-04
        • 2014-01-16
        • 2013-09-03
        • 1970-01-01
        相关资源
        最近更新 更多