【发布时间】:2020-08-06 09:58:26
【问题描述】:
我正在使用 icomoon 作为我的图标库
我正在尝试通过属性data-icon 动态设置图标。
但使用attr(data-icon) 似乎无法将内容识别为字符集。
有没有办法使用attr() 将\e92c 设为字符而不是字符串文字?
#expected::before {
content: '\e92c';
font-family: 'icomoon';
}
[data-icon]::before {
content: attr(data-icon);
font-family: 'icomoon';
}
<h2>This is what I expected</h2>
<a class="button" id="expected" href="javascript: void(0)">Save</a>
<h2>This is what I get :(</h2>
<a class="button" data-icon="\e92c" href="javascript: void(0)">Save</a>
【问题讨论】: