Ada*_*dam 5 css html5 escaping character-encoding special-characters
我正在使用webfont图标.图标字形映射到Unicode的补充专用区-A和B.
如果我通过data-*属性将字符传递给CSS,一切正常:
<div class="icon" data-icon="󰁚"></div>
Run Code Online (Sandbox Code Playgroud)
然后:
.icon::before {
font-family: IconFont;
content: attr(data-icon)
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试直接在CSS中嵌入转义字符...
.icon::before {
font-family: IconFont;
content: '\0F005A ';
}
Run Code Online (Sandbox Code Playgroud)
它显示为缺少的符号问号.
但如果我尝试不同的特殊角色......
.icon::before {
font-family: IconFont;
content: '\F8FF ';
}
Run Code Online (Sandbox Code Playgroud)
它工作正常!
我在规范中找不到任何说不可能的东西......它似乎不起作用.
有人对此有任何见解吗?
访问 Icomoon 将您的图标字体映射到私人使用区域。当你下载字体时,keyamoon已经提供了html,其中有两种显示特殊字符的方法。
方法1(来自CSS-tricks)并包含在Icomoon下载中:
<i aria-hidden="true" data-icon=""></i>
......
[data-icon]:before {
font-family: 'icomoon';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
Run Code Online (Sandbox Code Playgroud)
Icomoon 的方法 2 :
<span aria-hidden="true" class="icon-pencil"></span>
......
.icon-pencil, .icon-folder {
font-family: 'icomoon';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
.icon-pencil:before {
content: "\e000";
}
.icon-folder:before {
content: "\e001";
}
Run Code Online (Sandbox Code Playgroud)
您实际上可以在 html 中使用任何标签;我同意 CSS-tricks 中的评论之一,即斜体标签在语义上可能是最好的,因为它在 html5 中被重新定义。我只是喜欢 i 图标。