unicode - 如何使用 SASS 制作一个通用的 Font Awesome mixin
问题描述
我正在尝试制作一个 SASS mixin,让我只指定 mixin 调用和 Unicode 编号。这种情况适用于图标将显示在项目之前的列表项目。
我的 SASS mixin 看起来像这样。我添加了两个font-family
选项以包含所有内容。如果这不是一个好主意,也许我会做一个if
声明或其他东西:
=faIconBefore($unicode)
display: inline-block
content: "\$unicode"
font-family: "Font Awesome 5 Free", "Font Awesome 5 Brands"
font-size: 0.9em
font-style: normal
font-weight: 900
font-variant: normal
color: $colorPrime
text-rendering: auto
-webkit-font-smoothing: antialiased
margin-right: 0.25em
这可以在代码中用于下载图标,如下所示:
+faIconBefore('f019')
我也尝试在内容行中使用它:
content: "\#{$unicode}"
理想情况下,这只会添加我想要的图标,但是我会得到$unicode item.pdf
我的结果。
将 Unicode 数字硬编码到 SASS 文件中时它工作正常,但我似乎无法让这部分工作。
更新:
我试图拼凑一个fiddle,但它根本无法与字体一起使用。
解决方案
好吧,看起来那是行不通的。也许使用该@extend
命令,但更改content
mixin 中的样式以删除单引号和斜杠('\')并将斜杠添加到样式表中的 Unicode 编号似乎可以修复它。这是我的新代码:
// Adding a Font Awesome icon before an element, specifying the unicode number - Usage: +faIconBefore('\f019')
=faIconBefore($unicode)
display: inline-block
content: $unicode
font-family: "Font Awesome 5 Free", "Font Awesome 5 Brands"
font-size: 0.9em
font-style: normal
font-weight: 900
font-variant: normal
color: $colorPrime
text-rendering: auto
-webkit-font-smoothing: antialiased
margin-right: 0.25em
以及用法:
+faIconBefore('\f019')
如果有人知道它如何使用一些改进,请告诉我。
谢谢
推荐阅读
- apache-kafka-streams - Kafka Streams:为一组消息中的每条消息添加序列
- javascript - 在 IIFE 中使用 React Hooks 打破了 hooks 规则
- javascript - 从 Javascript fetch 中获取数据并将其显示在另一个函数中
- java - 如何让我的 javafx 代码计算我点击图像的次数?
- sql - 我如何在 oracle 中按 15 分钟间隔分组?
- c# - 如何从 WPF 应用程序在 Revit API 中引发外部事件?
- gitlab - Webhook 中的 Git 实验室集内容类型
- javascript - 将变量值分配给内部 html Spring MVC 标记值
- json - 输入'列表
' 不是类型 'List 的子类型 ' - variables - Haskell:用变量名替换字符