你能在 CSS 的“content”属性中使用 HTML 实体吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7240520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you use HTML entities in the CSS “content” property?
提问by clamp
I would like to use HTML entities in CSS, but it shows me the •
instead.
我想在 CSS 中使用 HTML 实体,但它显示了我•
。
.down:before{
content:"• ";
color:#f00;
}
Also, why does the above code not work in IE? it does not show the before part at all.
另外,为什么上面的代码在 IE 中不起作用?它根本不显示之前的部分。
回答by sandeep
put hex value of your bullet specail character like this
像这样输入你的子弹特殊字符的十六进制值
div:before{
content:"22";
color:#f00;
}
check this fiddle http://jsfiddle.net/sandeep/HPrkU/1/
检查这个小提琴http://jsfiddle.net/sandeep/HPrkU/1/
NOTE: after & before work in IE8
注意:在 IE8 中工作之后和之前
回答by twe4ked
I'm guessing you want the actual ?
character displayed, if so simply use the ?
character instead of •
.
我猜你想?
显示实际的字符,如果是这样,只需使用?
字符而不是•
.
Example: http://jsfiddle.net/rmjt8/
示例:http: //jsfiddle.net/rmjt8/
Edit:I found another thread: How can I include a HTML-encoded "content:" character in CSS?
编辑:我发现了另一个线程:如何在 CSS 中包含 HTML 编码的“内容:”字符?
Perhaps this will validate:
也许这会验证:
.down:before{
content:"22 ";
color:#f00;
}
回答by David says reinstate Monica
Assuming that you want the user to see the •
you can simply escape that sequence, to give:
假设您希望用户看到•
您可以简单地转义该序列,以给出:
.down:before{
content:"\• ";
color:#f00;
}
As to why it's not visible on IE7, that's because IE doesn't support generated content or the :before
selector.
至于为什么在 IE7 上看不到,那是因为 IE 不支持生成内容或:before
选择器。
Edited to offer that, to see the actual bullet character, you should use:
编辑以提供,要查看实际的项目符号字符,您应该使用:
.down:before{
content:"22";
color:#f00;
}
回答by Clement Herreman
You need to escape your entities:
你需要逃避你的实体:
.down:before{
content:"\• ";
color:#f00;
}
You cannot see it on IE because IE doesn't support :before (not :after)
你不能在 IE 上看到它,因为IE 不支持 :before (不是 :after)