css { content: "text"}, 如何添加标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3102259/
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
css { content: "text"}, How do i add tags?
提问by Matteo Mosca
I wrote some dummy css. Instead of a tag I got escaped characters. How can I add a div tag instead?
我写了一些虚拟 css。我得到了转义字符而不是标签。如何添加 div 标签?
.HeaderName:after{
content: "<div class=\"Name2\">text</div>";
}
.Name2 {
color: red;
}
回答by Matteo Mosca
The content
declaration cannot add tags to the page (tags are structural); additionally, CSS is meant for presentation changes, not structural content changes.
该content
声明不能添加标签页面(标签是结构性的); 此外,CSS 用于表示更改,而不是结构内容更改。
Consider using jQuery, instead, such as:
考虑使用 jQuery,例如:
$(".HeaderName").after("your html here");
回答by Dominic Cooney
You can't insert tags using content:
in CSS. Here is the relevant part of the spec; see the 'content' propertyin the CSS 2.1 spec.
你不能content:
在 CSS 中插入标签。这是规范的相关部分;请参阅CSS 2.1 规范中的“内容”属性。
回答by Omiod
If you need that extra tag only to make the added text red, just do this:
如果您只需要额外的标签来使添加的文本变为红色,请执行以下操作:
.HeaderName:after{
content: "text";
color:red;
}
Tested on Chrome.
在 Chrome 上测试。