Pseudo elements and attributes
A pseudo element may get it's content value from the element's attribute:
HTML
<a href="bar" class="foo">Hello</a>
CSS
.foo:after {
content: attr(href) /* this will return 'bar' */
}
This functionality can come handy in many situations, especially with the new data-name attribute available.
Example:
If you use a typeface for an icon. Let's say you have a 'Click me' button and you want to change that with the type-icon. The icon's character is for instance 'X'. Putting 'X' isn't really semantic, so what we do is this:
- Create a 'data-icon' attribute on the element with the value of 'X', leaving the element semantic
- In css, create the pseudo element, read the attribute value of 'data-icon' and switch the text with the icon (you can do this in many ways - indenting for one)
This is just one of many things. Try it out and embrace the capabilities :)
Written by Beno Rudolf
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Css
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#