uber5001
uber5001

Reputation: 3954

CSS psuedo-element content: attr(type)?

I just want a rule that acts like so:

div:before {
    content: "div";
}
span:before {
    content: "span";
}
a:before {
    content: "a";
}

but I want it to be generic for all element types, not just a div.

I want this...

*:before {
    content: attr(tagname); 
}

But tagname is not an attribute. Is there any way to get the element's type as a string in CSS?

Upvotes: 0

Views: 135

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201508

No, there is no way. Generated content can be specified in a few ways only. What you are trying to do requires client-side scripting, perhaps so that CSS rules are dynamically added to elements, and in the script code, you can use the tag name from the element node.

Upvotes: 1

Related Questions