使用方法
嵌入网页
在网页html中嵌入字体
在css代码中,我们主要使用的是font-face这个属性,它的主要功能就是把自己定义的Web字体嵌入到网页中。
- @font-face {
- font-family: <YourWebFontName>;
- font-family: <YourWebFontName>;
- [font-weight: <weight>];
- [font-style: <style>];
- } 其中关于属性的解释(有些可能没有用到)
- font-family:设置文本的字体名称。
- font-style: 设置文本样式。
- font-variant:设置文本是否大小写。
- font-weight:设置文本的粗细。
- font-stretch:设置文本是否横向的拉伸变形。
- font-size:设置文本字体大小。
- src:设置自定义字体的相对路径或者绝对路径,注意,此属性只能在@font-face规则里使用。
*.CSS文件内容
- @font-face {
- font-family: 'OnonSoninSans';
- src: url("./assets/font/OnonSoninSans.woff") format("woff"), //IE9+,Firefox3.5+,Chrome6+,Safari3.6+,Opera11.1+
- url("./assets/font/OnonSoninSans.ttf") format("truetype"), //IE9+,Firefox3.5+,Chrome4+,Safari3+,Opera10+,iOS Mobile Safari4.2+
- url("./assets/font/OnonSoninSans.otf") format("opentype"); // Firefox3.5+,Chrome4.0+,Safari3.1+,Opera10.0+,iOS Mobile Safari4.2+
- font-weight: normal;
- font-style: normal;
- }
所以根据这些,我们可以将字体文件放在指定的目录下,然后更改url的地址,对你的字体命名。然后,像正常字体一样去使用它吧。