【问题标题】:font-awesome with sass in a content cssfont-awesome with sass in a content css
【发布时间】:2016-04-21 17:25:21
【问题描述】:

我检查了几个主题,这个主题有点新,我发现了一个类似但不一样的案例。

所以,我的项目与 sass 和 font-awesome 完美配合。

我正在导入字体很棒的 scss 文件:

//libs
@import "css/font-awesome/scss/font-awesome";

我正在使用我的 sass 类

&:hover { 
    font-family: FontAwesome;
    content: $fa-var-android;
}

我不想使用 font-family: FontAwesome;在每一堂课中,都有这样的使用方式吗?

&:before {
    content: $fa-var-android;
}

或者更好:只是 unicode?​​p>

&:hover {
    content: '\f26e';
}

我试过了,但没有成功,有人可以帮我吗?

谢谢。

【问题讨论】:

  • 您需要添加字体系列,否则将无法使用
  • 如果你愿意,你可以这样做:&:hover, &:before, & { font-family: FontAwesome }
  • 感谢 cmets,但我怎么能做到这一点,有什么例子吗?我想在我的课程中停止使用 font-family : FontAwesome。

标签: css fonts sass font-awesome


【解决方案1】:

这是一个使用字体系列的通用类的解决方案。

HTML

<div class="a b">

</div>

CSS

.a{
  font-family: FontAwesome;
}
.b:before{
  content: '\f26e';
}
.b:hover:before{
  content: '\f2a3';
}

【讨论】:

    【解决方案2】:
    &:hover {
    content: '\f26e';
    }
    &:before {
    content: '\f003';
    }
    &:hover, &:before {
    font-family: FontAwesome
    }
    

    这样你就可以在逗号后面添加你想要的所有类和伪类,并一次性包含字体系列!

    【讨论】:

      【解决方案3】:

      我会为此创建一个mixin,并在其中包含mixin FontAwesome family-font 和content 变量:

      $icon: 'bar';
      $icon-2: 'baz';
      
      @mixin fa($icon){
          font-family: FontAwesome;
          content: $icon;
      }
      
      .foo{
        @include fa($icon);
      
        &:before{
          @include fa($icon-2);
        }
      }
      

      还有输出:

      .foo {
        font-family: FontAwesome;
        content: "bar";
      }
      
      .foo:before {
        font-family: FontAwesome;
        content: "baz";
      }
      

      【讨论】:

        【解决方案4】:

        感谢您的帮助,我同意上面的答案,但这些仅适用于少数类而不是我的所有 css。明白吗?

        所以我找到了一个更好的方法来做到这一点:

        body {
          font-family:  FontAwesome,Helvetica;
        }
        

        这样我就可以使用 unicode 和变量,而且我不需要在我的类中编写 font-family。

        &:before {
            content: $fa-var-android;
        }
        
        
        &:hover {
            content: '\f26e';
        }
        

        谢谢。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-05-02
          • 1970-01-01
          • 2015-02-22
          • 1970-01-01
          • 2016-05-09
          • 1970-01-01
          • 2015-04-30
          相关资源
          最近更新 更多