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

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

css { content: "text"}, How do i add tags?

css

提问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 contentdeclaration 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 上测试。