CSS内容属性:是否可以插入HTML而不是文本? [英] CSS content property: is it possible to insert HTML instead of Text?

查看:117
本文介绍了CSS内容属性:是否可以插入HTML而不是文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否可能以某种方式使 content 属性插入html代码而不是字符串:before :之后元素如:

Just wondering if it's possible somehow to make the CSS content property insert html code instead string on :before or :after an element like:

.header:before{
  content: '<a href="#top">Back</a>';
}

这将是非常方便...它可以通过Javascript,但使用css为这将真的让生活更容易:)

this would be quite handy...It could be done through Javascript but using css for this would really make lives easier :)

推荐答案

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

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:

这篇关于CSS内容属性:是否可以插入HTML而不是文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆