700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > @font-face(css3属性)实现在网页中嵌入任意字体

@font-face(css3属性)实现在网页中嵌入任意字体

时间:2018-11-16 07:43:00

相关推荐

@font-face(css3属性)实现在网页中嵌入任意字体

@font-face语法规则

@font-face {font-family: <YourWebFontName>;src: <source> [<format>][,<source> [<format>]]*;[font-weight: <weight>];[font-style: <style>];}

说明:

YourWebFontName:此值指的就是你自定义的字体名称,最好是使用你下载的默认字体,他将被引用到你的Web元素中的font-family。如“font-family:"YourWebFontName";”

source:此值指的是你自定义的字体的存放路径,可以是相对路径也可以是绝路径;

format:此值指的是你自定义的字体的格式,主要用来帮助浏览器识别,其值主要有以下几种类型:truetype,opentype,truetype-aat,embedded-opentype,avg等;weight和style:这两个值大家一定很熟悉,weight定义字体是否为粗体,style主要定义字体样式,如斜体。

实例:(以SingleMaltaRegular为例)

下载所需要的字体。

获得@font-face所需的.eot,.woff,.ttf,.svg字体格式字体。可以在这个网站上搞定。点击进入(fontsquirrel)

FontSquirrel下载文件到本地的电脑上了,解压。即可得到字体。

在项目中新建文件夹fonts,讲下载字体放进去。

样式书写格式:

@font-face {font-family: 'SingleMaltaRegular'; src: url('../fonts/singlemalta-webfont.eot'); src: url('../fonts/singlemalta-webfont.eot?#iefix') format('embedded-opentype'),url('../fonts/singlemalta-webfont.woff') format('woff'), url('../fonts/singlemalta-webfont.ttf') format('truetype'), url('../fonts/singlemaltawebfont.svg#SingleMaltaRegular') format('svg'); font-weight: normal; font-style: normal;}

最后即可引用的字体:

body{font-family: 'SingleMaltaRegular'}

注:通过网站下载的文件里,会自动生成样式,从而直接拷贝即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。