CSS:对内容中的字符进行编码后
我正在使用以下CSS,它似乎有效:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
但是字符似乎不能像这样编码,因为输出是文字并显示实际字符串:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
如果我无法对其进行编码,感觉我应该使用一些东西例如 jQuery 中的 .append(),因为它支持编码。有什么想法吗?
I am using the following CSS, which seems to be working:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
The characters however cannot seem to be encoded like this, as the output is literal and shows the actual string:
a.up:after{content: " ↓";}
a.down:after{content: " ↑";}
If I can't encode it, it feels like I should use something such as .append() in jQuery, as that supports the encoding. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要在
content
中使用编码的 Unicode 字符,您需要提供字符本身(就像您所做的那样),或其 UTF-8 转义序列而不是 HTML 实体:To use encoded Unicode characters in
content
you need to provide either the characters themselves (as you do), or their UTF-8 escape sequences instead of HTML entities:为什么要对这些字符进行编码?请记住,您正在编写 CSS,而不是 HTML。您的代码:
完全有效,只要您使用 UTF-8 编码保存文件并发送适当的标头:
编码字符仅在 HTML 中使用,以便内容和标签之间不会出现歧义。因此,您可以将
<
编码为<
,这样浏览器就不会认为它是标记的开头。像↓
这样的东西只是那些不知道如何使用 utf-8(或者出于某种原因不能使用)的人的商品:)。Why do you want to encode those characters anyway? Remember, you're writing CSS, not HTML. Your code:
is perfectly valid, as long as you save the file with UTF-8 encoding and send the appropriate header:
Encoding characters is only used in HTML so that there is no ambiguity between content and tags. Thus, you would encode
<
as<
so that the browser doesn't think it's the beginning of a tag. Stuff like↓
are just commodities for people who don't know how to use utf-8 (or can't, for whatever reason) :).只是想补充一下,如果您想通过
attr() 函数
,上面的方法不起作用。看Just want to add that if you want to set dynamically the value of
content
viathe attr() function
, the above won't work. See