字体真棒 &统一码 [英] Font Awesome & Unicode

查看:30
本文介绍了字体真棒 &统一码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站中使用(优秀的)Font-Awesome,如果我这样使用它,它运行良好:

I'm using (the excellent) Font-Awesome in my site, and it's working fine, if I use it this way:

<i class="icon-home"></i>

但是(出于某些原因)我想以 Unicode 方式使用它,例如:

But (for some reasons) I want to use it in the Unicode way, like:

<i>&#xf015;</i>

(Font Awesome 的备忘单)

但它不起作用 - 浏览器显示的是一个正方形.

But it doesn't work - the browser shows a square instead.

我该如何解决这个问题?CSS 路径是正确的(作为使用 Font Awesome 的第一种方法).

How do I solve this? The CSS path is correct (as the first way of using Font Awesome works).

我确实安装了 FontAwesome.otf.

I do have the FontAwesome.otf installed.

推荐答案

它不起作用,因为 &#xf015;</i> 只是要求浏览器显示使用斜体字体的 Private Use 代码点 U+F015.Font Awesome CSS 代码对此没有任何影响.如果您将 class=icon-home 添加到标记中,您将在 FontAwesome 字体中获得分配给 U+F015 的字形,但由于 Font Awesome 诡计的工作方式,您将获得两次.

It does not work, because <i>&#xf015;</i> simply asks the browser to display the Private Use code point U+F015 using an italic typeface. The Font Awesome CSS code has nothing that would affect this. If you add class=icon-home to the tag, you will get the glyph assigned to U+F015 in the FontAwesome font, but you will get it twice, due to the way the Font Awesome trickery works.

要仅获取一次字形,您需要使用 CSS 来要求使用 FontAwesome 字体,而不会触发通过生成的内容添加字形的规则.一个简单的技巧是使用以 icon- 开头的类名,但与 Font Awesome 中的任何预定义名称或 CSS 或 JavaScript 代码中以其他方式使用的任何名称都不匹配.例如,

To get the glyph just once, you need to use CSS that asks for the use of the FontAwesome font without triggering the rules that add a glyph via generated content. A simple trick is to use a class name that starts with icon- but does not match any of the predefined names in Font Awesome or any name otherwise used in your CSS or JavaScript code. E.g.,

<i class=icon-foo>&#xf015;</i>

或者,使用在 i 元素上设置 font-family: FontAwesomefont-style: normal 的 CSS 代码.

Alternatively, use CSS code that sets font-family: FontAwesome and font-style: normal on the i element.

附注.请注意,根据定义,U+F015 等专用代码点没有可互操作的含义.因此,当样式表被禁用时,&#xf015; 将不会显示为任何字符;浏览器将使用其传达未定义数据的方式,例如一个可能包含代码点编号的小盒子.

PS. Note that Private Use code points such as U+F015 have, by definition, no interoperable meaning. Consequently, when style sheets are disabled, &#xf015; will not be displayed as any character; the browser will use its way of communicating the presence of undefined data, such as a small box, possibly containing the code point number.

这篇关于字体真棒 &amp;统一码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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