字体内的图标对网站有用吗?
我想创建仅包含图标的特殊字体。每个字母都有不同的图标。 我想把这个字体嵌入到css中。 并像这样使用 如果我需要一些图标:
<a class="icon">f</a>
和包含以下内容的CSS
<link href='http://fonts.mysite.com/css?family=MyFontWithIcons' rel='stylesheet' type='text/css'>
:
@media screen {
@font-face {
font-family: 'MyFontWithIcons';
font-style: normal;
font-weight: normal;
src: local('MyFontWithIcons'), url('http://fonts.mysite.com/font?MyFontWithIcons') format('truetype');
}
}
并显示带有图标类的图标:
.icon {font-family: 'MyFontWithIcons'; }
并且字母“f”将被替换为位于f字母位置的字体内的图标。 css 与字体一起使用,并将 f 替换为字体内的图标。 我认为这是好主意还是坏主意?字体文件的大小比许多图像图标小。 而且通过这种技术,我可以使用不同的字体颜色=不同的图标颜色?尺寸等。 那么,这是好主意还是坏主意?
I wanna create special font containing only icons. and for each letter will be diffirent icon.
I want to embed this font in css.
and use like this
if i need some icon:
<a class="icon">f</a>
and css
<link href='http://fonts.mysite.com/css?family=MyFontWithIcons' rel='stylesheet' type='text/css'>
which contains:
@media screen {
@font-face {
font-family: 'MyFontWithIcons';
font-style: normal;
font-weight: normal;
src: local('MyFontWithIcons'), url('http://fonts.mysite.com/font?MyFontWithIcons') format('truetype');
}
}
and to show icons with icon class:
.icon {font-family: 'MyFontWithIcons'; }
And letter "f" will be replaced with icon inside font which located on the place of f letter.
and css works with font and replacing f with icon inside font.
I think it's good idea or not? font file is less in size than lots of image icons.
and also with this technique I can use diffirent font colors = diffirent icon colors? sizes and so on.
So, it's good idea or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用图标的自定义字体的问题是,如果出现以下情况,您将没有备份计划:
@font-face
出于这个原因,图像提供了
alt
属性。但是,如果您要使用图标字体,请确保将字形存储在 Unicode 私人使用区域。这将通过确保可能没有冲突来稍微缓解问题(公司有时可以并且确实使用 PUA 字形来存储自定义数据),并且如果它们编码得巧妙,屏幕阅读器可以知道如何优雅地忽略 PUA 字形。
至于实现后备,我建议使用 Modernizr (具体来说,Modernizr.fontface) 来测试支持。
The problem with using a custom font for icons is that you've got no backup plan if:
@font-face
@font-face
(Eg. Textual web browsers like Lynx, Links2, and ELinks for Unix/Linux)Images provide the
alt
attribute for just this reason.However, if you're going to use a font for icons, make sure you store your glyphs in a Unicode Private Use Area. That'll mitigate the problem a bit by ensuring there's probably no conflict (Companies can and do sometimes use PUA glyphs to store custom data) and, if they're coded smartly, screen readers could know to gracefully ignore PUA glyphs.
As for implementing a fallback, I'd suggest using Modernizr (specifically, Modernizr.fontface) to test for support.
这是一个好主意,但它不适用于所有浏览器(目前)。此外,它仅适用于 2 种彩色图像(黑色和透明),这使得它相当有限。对于拥有文本浏览器或文本转语音软件的人来说,这没有任何意义。它并不是真正的“语义”,因为
标签是用于图像的。从纯 html 的角度来看,使用字体没有任何意义。它还会让你的 CSS 变得混乱。
因此,仅仅减少一点带宽就会带来很多不好的事情;我不会打扰。
It's a good idea but it doesn't work in all browsers (yet). Also, it only works with 2 color images (black and transparent), which makes it rather limited. For people with text browsers or text to speech software, it won't make any sense. It's not really 'semantic', because the
<img>
-tag was meant for images. Using fonts for that won't make any sense from a html-only perspective. It also clutters your css.So that's a lot of bad things just for a little bit less bandwith; I wouldn't bother.
@font-face
并未在各浏览器中得到统一支持。迎合所有浏览器是一项艰巨的任务,尤其是。如果包括 IE6@font-face
is not supported uniformly across browsers. Its a bit of a task to cater to all browsers esp. if including IE6所有其他答案都集中在缺点上。
我个人非常喜欢使用图标字体。
以下是使用图标字体的一些充分理由:
dark-theme
类,则所有图标均为白色,如果主体具有tropical-theme
类,则所有图标均为粉红色code>)All the other answers focus on the downsides.
I am, personally, a big fan of using icon fonts.
Here are some good reasons to use an icon font:
dark-theme
, and all icons are pink if body has classtropical-theme
)