html5 字体嵌入,网页中嵌入特殊字体(@font-face)

aff9f72ce5e96a0c1bdf543372de9ae7.png

这里主要用到@font-face这个语法。

假如我要使用一个open-sans字体,点击ADD FONTS按钮,并勾选Agreement,如下图

打开转换字体的网站http://www.fontsquirrel.com/tools/webfont-generator

6dba3918d6d8e9aff2b12e8208bc2cca.png

上传后,会自动生成所需eot,svg,ttf,woff,woff2 5种文件,

并且还有个CSS文件,直接包含调用以上5种文件,很方便

[css]

@font-face {

font-family: ‘open_sansregular’;

src: url(‘opensans-regular-webfont.eot’);

src: url(‘opensans-regular-webfont.eot?#iefix’) format(’embedded-opentype’),

url(‘opensans-regular-webfont.woff2’) format(‘woff2’),

url(‘opensans-regular-webfont.woff’) format(‘woff’),

url(‘opensans-regular-webfont.ttf’) format(‘truetype’),

url(‘opensans-regular-webfont.svg#open_sansregular’) format(‘svg’);

font-weight: normal;

font-style: normal;

}

[/css]

@font-face是CSS3的一个模块,它允许开发者自定义字体并将其嵌入网页。通过使用@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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值