tags:

views:

52

answers:

2

I wrote some dummy css. Instead of a tag i got escaped characters. How can i add a div tag instead?

.HeaderName:after{
content: "<div class=\"Name2\">text</div>";
}

.Name2 {
color: red;
}
+6  A: 

First of all, the content declaration cannot be used to add tags to the page, as tags are not "content" but structure.

Second, CSS is meant to style, not to define content. The content declaration shouldn't be used, imho.

You'd better use a line of jquery to achieve your purpose, something like:

$(".HeaderName").after("your html here");

It works and does not break up any conceptual rule. :)

Matteo Mosca
Lastly, text added via the CSS content property is not inserted into the DOM, so it can't be acted on later by Javascript, etc. I agree that it should not be used in general, and certainly should not be used for this purpose. +1
JacobM
In certain contexts, the use of the content property could be stylistically correct. For instance, adding a comma after certain pieces of content:<span class="city">New York</span><span class="state">NY</span>.city:after { content: ", "; }So, it's not _always_ wrong, but it's not by any means recommended.
Ryan Kinal
+1  A: 

You can't insert tags using content: in CSS. Here is the relevant part of the spec; see the 'content' property in the CSS 2.1 spec.

Dominic Cooney