首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在伪元素中选择正确的字体系列

在伪元素中选择正确的字体系列
EN

Stack Overflow用户
提问于 2018-06-04 20:02:17
回答 1查看 11K关注 0票数 11

我现在对在CSS伪元素中使用图标感到困惑。字库有四种:Font Awesome 5 FreeFont Awesome 5 SolidFont Awesome 5 BrandsFont Awesome 5 Regular

下面是HTML:

代码语言:javascript
复制
<h1>Hello</h1>

案例1

我使用这个图标:https://fontawesome.com/icons/twitter?style=brands

如你所见,它是一个字体图标,所以brands -family:Font Awesome 5 Brands

代码语言:javascript
复制
h1:before {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  content: "\f099"; /* TWITTER ICON */
  font-family: "Font Awesome 5 Brands";
  font-weight: 400;
}

它起作用了!

案例2

我使用这个图标:https://fontawesome.com/icons/phone?style=solid

如你所见,它是一个字体图标,所以solid -family:Font Awesome 5 Solid

代码语言:javascript
复制
h1:before {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  content: "\f095"; /* PHONE ICON */
  font-family: "Font Awesome 5 Solid";
  font-weight: 900;
}

不起作用!

我做错什么了?

我们如何知道何时使用正确的字体系列?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 20:06:21

只需在同一个font-family中使用它们,浏览器就可以完成这项工作。如果它在第一个中找不到它,它将使用第二个。(Multiple fonts in Font-Family property?)

顺便说一句,正确的font-familyFree而不是Solid,因为Solid和Regular之间的区别是font-weight,并且两者具有相同的font-family字体家族中没有 SolidRegular,只有FreeBrands

你可能还注意到,几乎所有Solid版本的图标都是免费的,但并非所有的regular版本都是免费的。其中一些包含在PRO包中。如果图标没有显示,则不一定是a font-family问题。

所有的Lightduotone版本都是PRO版本。

代码语言:javascript
复制
.icon {
  display: inline-block;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
  font-family: "Font Awesome 5 Brands","Font Awesome 5 Free";
}

.icon1:before {
  content: "\f099";
  /* TWITTER ICON */
  font-weight: 400;
}

.icon2:before {
  content: "\f095";
  /* PHONE ICON */
  font-weight: 900;
}

.icon3:before {
  content: "\f095";
  /* PHONE ICON */
  font-weight: 400;/*This one will not work because the regular version of the phone icon is in the Pro Package*/
}
代码语言:javascript
复制
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.0/css/all.css" >

<div class="icon1 icon"></div>
<div class="icon2 icon"></div>
<br>

<div class="icon3 icon"></div>

参考:https://fontawesome.com/how-to-use/on-the-web/advanced/css-pseudo-elements#define

font-weight问题相关的问题:Font Awesome 5 on pseudo elements shows square instead of icon

票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50680160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档