图标字体:它们是如何工作的? [英] Icon Fonts: How do they work?

查看:29
本文介绍了图标字体:它们是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道图标字体只是字体,您可以通过调用它们的类名来获取图标,但是图标字体如何工作?

我已尝试检查 Chrome 中加载的相关图标字体资源,以查看图标字体如何显示图标(与一般字体相比),但我无法弄清楚这是如何发生的.

我也没有成功找到有关如何完成这种图标字体技术"的资源,即使有很多 )do涉及下载特定字体并使用 content 属性,例如:

@font-face {...src: url('../font/fontawesome-webfont.eot?#iefix&v=3.0.1') 格式('embedded-opentype'),url('../font/fontawesome-webfont.woff?v=3.0.1') 格式('woff'),url('../font/fontawesome-webfont.ttf?v=3.0.1') 格式('truetype');...}.icon-beer:before {内容:f0fc";}

由于 content 属性在旧浏览器中不受支持,这些利用了图像.

这是一个完全原始的 FontAwesome 用作字体的例子,将 ( - 你可能看不到这个!)变成一辆救护车:http://jsfiddle.net/GWqcF/2

I understand that icon fonts are just fonts and that you can get the icons by just calling their classname, but how do icon fonts work?

I've tried checking the related icon font resources loaded in Chrome to see how icon fonts display icons (in comparison to general fonts) but I haven't been able to figure out how this happens.

I've also been unsuccessful in finding resources on how this "icon font technique" is done, even though there are loads of icon fonts available. There are also loads of resources showing how icon fonts can be integrated, but no one seems to be sharing or writing about how this is done!

解决方案

Glyphicons are images and not a font. All the icons are found within a sprite image (also available as individual images) and they are added to the elements as positioned backround-images:

Actual font icons (FontAwesome, for instance) do involve downloading a specific font and make use of the content property, for instance:

@font-face {
    ...
    src: url('../font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
         url('../font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
         url('../font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
    ...
}

.icon-beer:before {
    content: "f0fc";
}

As the content property isn't supported in older browsers, these also make use of images.

Here's an example of completely raw FontAwesome in use as a font, turning  ( - you may not be able to see this!) into an ambulance: http://jsfiddle.net/GWqcF/2

这篇关于图标字体:它们是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆