CSS“内容”属性中的HTML特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4476322/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:21:08  来源:igfitidea点击:

HTML special characters in CSS "content" attribute

cssxhtmlcharacter

提问by sethvargo

I'm trying to add content to something before an item using the CSS :before + content: fields. I want to insert a checkmark (☑), BUT if I use that in the content option, it prints as the literal. How can I tell CSS to make that a checkmark, not the literal string ☑?

我正在尝试使用 CSS :before + content: 字段在项目之前添加内容。我想插入一个复选标记 (☑),但是如果我在内容选项中使用它,它会打印为文字。我如何告诉 CSS 将其设为复选标记,而不是文字字符串 ☑?

回答by Flack

Try this:

尝试这个:

#target:before {
  content: "11";
}

回答by Brad Mace

You need to use Unicodevalues inside the contentproperty. (The list of miscellaneous symbolsmay also be useful.)

您需要在属性中使用Unicodecontent。(杂项符号列表也可能有用。)

A heavy checkmark is listed as U+2713so you would put content: "\2713";

列出了一个沉重的复选标记,U+2713所以你会放content: "\2713";

回答by Yi Jiang

Use the checkbox character literally in your CSS rule instead of the encoding -

在 CSS 规则中逐字使用复选框字符而不是编码 -

#target:before {
    content: "?";
}

See: http://jsfiddle.net/e3Wt2/

见:http: //jsfiddle.net/e3Wt2/