Web page Production WEBJX article introduction: in a project, once to use:: Selection pseudo element, and then the development classmate asked me, CSS in a colon and two colon god horse difference? |
In a project, once to use:: Selection pseudo element, and then the development classmate asked me, CSS in a colon and two colon god horse difference?
This seems to be really a problem, perhaps a lot of front-end students have doubts about it, looked up some data to confirm the difference between the next two symbols, in short: single colon (:) for CSS3 pseudo class, double colon (::) used to CSS3 pseudo element .
There is a description in the specification of the CSS3 selector for the consortium :
A Pseudo-element is made of two colons (::) followed by the name of the pseudo-element. This:: Notation are introduced by the current document in order to establish a discrimination between pseudo-classes and P Seudo-elements. For compatibility with existing style sheets, user agents must also accept the previous One-colon notation for Pseudo-elem Ents introduced in CSS levels 1 and 2 (namely,: First-line,: First-letter,: Before And:after). This compatibility isn't allowed for the new pseudo-elements introduced at CSS Level 3.
Simply translated, the effect is that pseudo elements consist of double colons and pseudo element names. Double colons are introduced in the current specification to differentiate between pseudo classes and pseudo elements. However, the pseudo class compatible with existing styles, browsers need to support the old pseudo class, such as: First-line,: First-letter,: Before, after and so on.
So now you can fully answer the question in the title, for CSS2 before the pseudo elements, such as: before, single colon and double colon:: Before function is the same .
So, if your site only needs to be compatible with WebKit, Firefox, Opera and other browsers, it is recommended to use double colon for pseudo elements, if you have to be compatible with IE browser, or use CSS2 single colon to be more secure.