Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

什么是@font-face? #2

Open
kaneruan opened this issue Feb 2, 2016 · 4 comments
Open

什么是@font-face? #2

kaneruan opened this issue Feb 2, 2016 · 4 comments

Comments

@kaneruan
Copy link
Member

kaneruan commented Feb 2, 2016

@font-face是css3的一个模块,常用于Logo,tags

@font-face {
       font-family: <YourWebFontName>;
       src: <source> [<format>][,<source> [<format>]]*;
       [font-weight: <weight>];
       [font-style: <style>];
     }
  • YourWebFontName:此值指的就是你自定义的字体名称,最好是使用你下载的默认字体(下载回来的叫什么字体,这里就填什么字体名),他将被引用到你的Web元素中的font-family。如“font-family:"YourWebFontName";”
  • source:此值指的是你自定义的字体的存放路径,可以是**_相对路径**_也可以是**绝对路径**
@kaneruan
Copy link
Member Author

kaneruan commented Feb 2, 2016

其次是format自定义字体格式,主要用来帮助浏览器识别,有一下类型

  • TrueType:即.ttf格式
  • OpenType:即.otf
    -Web Open Font Format:即.woff,.woff字体是Web字体中最佳格式,他是一个开放的TrueType/OpenType的压缩版本,同时也支持元数据包的分离
  • Embeded Open Type:即.eot
  • SVG:.svg字体是基于SVG字体渲染的一种格式,支持这种字体的浏览器

@kaneruan
Copy link
Member Author

kaneruan commented Feb 2, 2016

这就意味着在@font-face中我们至少需要.woff,.eot两种格式字体,甚至还需要.svg等字体达到更多种浏览版本的支持

@kaneruan
Copy link
Member Author

kaneruan commented Feb 2, 2016

.eot字体是IE专用字体,可以从TrueType创建此格式字体,支持这种字体的浏览器有【IE4+】

@kaneruan
Copy link
Member Author

kaneruan commented Feb 2, 2016

阿里图标字体库
下面是一个例子

@font-face {font-family: 'webfont';
  src: url('//at.alicdn.com/t/eb26m88i104o0f6r.eot'); /* IE9*/
  src: url('//at.alicdn.com/t/eb26m88i104o0f6r.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('//at.alicdn.com/t/eb26m88i104o0f6r.woff') format('woff'), /* chrome、firefox */
  url('//at.alicdn.com/t/eb26m88i104o0f6r.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
  url('//at.alicdn.com/t/eb26m88i104o0f6r.svg#思源黑体-极细') format('svg'); /* iOS 4.1- */
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant