Atadj
Atadj

Reputation: 7180

Can CSS :after contain content of this element?

Quick and simple question. Let's say I have this link: <a href="">abc</a>

Can I use abc as content of a:after { content: ???; } anyhow? I don't want to create additional data-myattr.

W3 says something like this:

attr(X) This function returns as a string the value of attribute X for the subject of the selector. The string is not parsed by the CSS processor. If the subject of the selector does not have an attribute X, an empty string is returned. The case-sensitivity of attribute names depends on the document language.

http://www.w3.org/TR/CSS2/generate.html#propdef-content

Upvotes: 1

Views: 168

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201588

No, it is not possible, so it’s better to consider the original problem, for which this was an assumed solution.

In the CSS3 Generated and Replaced Content Module draft, there is the possibility of using content: contents for an :after pseudo-element, but this would only work if this was the only use of the element’s content (you would have content: none for the real element), i.e. it is not meant for duplicating the content. Moreover, it’s a very outdated module, and most of its proposed novelties (including this) have no known implementations.

Upvotes: 1

Daniel Williams
Daniel Williams

Reputation: 8885

You can put strings into content:. This is the relevant documentation about it: http://www.w3.org/TR/CSS2/syndata.html#strings

Upvotes: 0

Related Questions