css 使用@font-face 嵌入自定义字体或字体图标方法笔记

通常css使用font-family指定客户端显示字体的样式,本笔记目的在于解决客户端未安装指定字体,导致无法完成设计效果要求。与此同时现在大部分图标使用字体格式,因为它有矢量,体积小等等优点讲解如何使用字体图标

下面是详细的方法步骤:

1、制作或下载字体文件

由于浏览器对@font-face的兼容问题,这里涉及到一个字体format的问题,因为不同的浏览器对字体格式支持是不一致的,所以需要转换出多种字体格式文件以便兼容尽可能多的浏览器

2、使用第三方平台转换字体文件为font-face所支持的格式

TureTpe(.ttf)格式:
OpenType(.otf)格式:
Web Open Font Format(.woff)格式:
Embedded Open Type(.eot)格式:
SVG(.svg)格式:

步骤为先上传图片字体文件,然后选择要转换的几种格式下载


3、引入字体文件

@font-face {
  font-family: "FamilyName";
  src: url("path.eot");
  src: url("path/to/*.eot?#iefix") format("embedded-opentype"), 
  url("path/to/*.woff") format("woff"), 
  url("path/to/*.ttf") format("truetype"), 
  url("path/to/*.svg#FamilyName") format("svg");
  font-weight: normal;
  font-style: normal;
}

FamilyName 会在刚刚下载的文件中的css文件中有,你可以直接使用下载文件不用再定义样式,我这里是为说明原理所以不使用下载的css


4、使用字体文件

a、 字体
直接style="font-family:FamilyName" 或直接class 内定义使用到指定元素上
b、 图标
定义通用图标样式

[class*="foundicon-"] {
  display: inline;
  width: auto;
  height: auto;
  line-height: inherit;
  vertical-align: baseline;
  background-image: none;
  background-position: 0 0;
  background-repeat: repeat;
}

[class*="foundicon-"]:before {
  font-family: "FamilyName";
  font-weight: normal;
  font-style: normal;
  text-decoration: inherit;
}
[class*="general foundicon-"]:before {
    font-family: "FamilyName";
}

定义图标:

.foundicon-thumb-up:before {
  content: "\f000";
}

.foundicon-thumb-down:before {
  content: "\f001";
}
…………

使用:

<i class="general foundicon-thumb-up"></i> 

参考博客:

http://blog.csdn.net/chelen_jak/article/details/19125507









  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
@font-faceCSS3中的一个模块,它允许开发者自定义字体并将其嵌入到网页中。通过使用@font-face,你可以在网页中使用非Web安全字体,从而实现更多样化的字体效果。\[3\] @font-face的语法规则如下: @font-face { font-family: <YourWebFontName>; /* 自定义字体名称 */ src: <source> \[<format>\]\[, <source> \[<format>\]\]*; /* 自定义字体的存放路径、格式 */ \[font-weight: <weight>\]; /* 定义字体是否为粗体 */ \[font-style: <style>\]; /* 定义字体样式,如斜体 */ } 其中,font-family用于定义自定义字体的名称,src用于指定自定义字体的存放路径和格式,format参数主要用于帮助浏览器识别字体格式。font-weight用于定义字体是否为粗体,font-style用于定义字体样式,如斜体。\[2\] 通过使用@font-face,你可以在CSS中引用自定义字体,并在网页中应用这些字体,从而实现更丰富的字体效果。 #### 引用[.reference_title] - *1* [用 @font-face 实现自定义字体](https://blog.csdn.net/huangpb123/article/details/104231496)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [@font-face使用自定义字体](https://blog.csdn.net/weixin_50561836/article/details/114108305)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [css3中@font-face模块自定义字体](https://blog.csdn.net/anmi3721/article/details/101666350)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_________MAN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值