I wrote a class with content but seems content just work for pseudo-classes.
How to modify my code?
http://jsfiddle.net/fuRKC/
button.follow{
content: 'Follow';
}
button.followed{
content: 'Unfollow';
}
The :not() pseudo-class requires a comma-separated list of one or more selectors as its argument. The list must not contain another negation selector or a pseudo-element.
The :not pseudo-class represents an element that is not represented by its argument.
::before (:before) In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
The :has() CSS pseudo-class represents an element if any of the selectors passed as parameters (relative to the :scope of the given element) match at least one element.
By current CSS specifications, the content
attribute only applies to :before
and :after
pseudo-elements. There is an old proposed extension, CSS3 Generated and Replaced Content Module, which would allow the property to apply to real elements, too. The proposal is however ten years old. It has only been implemented in Opera, except for the special case where the content
value is an URL expression, interpreted as referring to an image – this is supported by Chrome and Safari, too.
Moreover, even the limited support wouldn’t do much good here, since the extension does not seem to work on Chrome when the element is a button, and on Opera, the generated content appears as such, not within a button widget.
Since your button
elements have empty content, you don’t really need the extension, since for empty content, adding content is equivalent to replacing content. So in this case, you would just need to use button.follow:before
, as in Kippie’s answer. Note, however, that this means that the button appears as completely empty when CSS is disabled.
So whatever might be the reason for using generated content, instead of button text in HTML, a more robust approach would be to change content with JavaScript. JavaScript can be disabled, of course, but you can use actual button text as fallback, e.g. <button id=follow>Follow</button>
, and replace the content when JavaScript is enabled.
You are correct. content
only works with the :before
and :after
pseudo classes.
Just make your css like this:
button.follow:before{
content: 'Follow';
}
button.followed:before{
content: 'Unfollow';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With