【问题标题】:Why it displays character code instead of icon?为什么它显示字符代码而不是图标?
【发布时间】:2020-08-16 04:51:31
【问题描述】:

我正在尝试通过将符号图标的 unicode 十进制代码粘贴到 css ::before 伪类的 content 属性中来显示符号图标。

当我将它直接插入 html 时,它可以完美运行 <div class="response__info" before-att = "&#11088" after-att = "7.7">.

但是当我用 javascript 做同样的事情时,它会显示代码本身而不是实际的符号 infoElement.setAttribute('before-att', '&#x2b50');

这是我的 CSS

response__info::before{
content: attr(before-att);
}

【问题讨论】:

  • 如果你使用\u2B50,它会起作用吗?
  • 是的,非常感谢

标签: javascript html css webpack unicode


【解决方案1】:

使用 unicode \u2B50

document.querySelector('.response__info').addEventListener('click', event => event.target.setAttribute('before-att', '\u2B50'))
.response__info::before{
content: attr(before-att);
}
<div class="response__info" before-att = "X">Hello</div>

【讨论】:

    猜你喜欢
    • 2021-04-20
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2023-01-27
    • 2023-02-07
    • 1970-01-01
    相关资源
    最近更新 更多