且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CSS内容属性:是否可以插入HTML而不是文本?

更新时间:2023-11-07 12:46:22

不幸的是,这是不可能的。根据规范

Unfortunately, this is not possible. Per the spec:


生成的内容不会更改文档树。具体来说,它不会反馈给文档语言处理器(例如,用于重新解析)。

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

换句话说,对于字符串值这意味着值总是按字面处理。

In other words, for string values this means the value is always treated literally. It is never interpreted as markup, regardless of the document language in use.

例如,使用给定的CSS和以下HTML:

As an example, using the given CSS with the following HTML:

<h1 class="header">Title</h1>

...将产生以下输出:

... will result in the following output: