CSS: Should I use :before or ::before?
Question by WebHorn | 2014-09-09 at 23:27
Currently, I am trying to implement the pseudo-elements :before and :after in my webdesign, because I would like to insert some content with these selectors.
However, on different Internet pages, I have discovered divergent writings. Some designers are writing :before and :after with only one colon at the beginning, others are using a variant with two colons, they are writing ::before and ::after instead.
Which writing is correct and what should I use in my own CSS-Stylesheet for my website?
Related Topics
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
Website Performance: Deliver JavaScript and CSS files compressed to reduce loading times
Tutorial | 0 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
Reload Images, CSS, JS and Web Pages despite Browser Cache
Tip | 2 Comments
Darken Background of a Website (Gray Out Effect)
Tutorial | 0 Comments
CSS: Why is DarkGray brighter than Gray?
Info | 0 Comments
Mouseover buttons using CSS without reloading
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
CSS3 separates between pseudo-classes (:hover, :visited, :first-child, :nth-child etc) and pseudo-elements (::before, ::after, ::first-line etc).
This division is made visible with one or two colons in front of the notation. According to this specification, it would be more correct to choose the variant with two colons for "before" and "after".
In practice, many web designers are still using the old syntax with only one colon. The reason: Every browser supporting "::" is also supporting ":", but Internet Explorer 8 is only supporting the variation with one colon.
If you do not want to care about old browsers, you can calmed use "::", otherwise, you can always use ":".
2014-09-10 at 15:31