zanona zanona - 1 year ago 98
HTML Question

CSS content property: is it possible to insert HTML instead of Text?

Just wondering if it's possible somehow to make the CSS

property insert html code instead string on
an element like:

content: '<a href="#top">Back</a>';

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

Answer Source

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.

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

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

... will result in the following output:

<a href="#top">Back</a>Title

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download