Pseudo elements
- In the W3C CSS2.1 specification the syntax of pseudo elements and pseudo classes are the same, both starts with a colon (:) followed by the name of the pseudo (see: Pseudo-elements (W3C CSS21)).
- In the W3C CSS3 specification the syntax of pseudo elements was changed, a pseudo element starts with two colons (::) followed by the name of the pseudo (see: Pseudo-elements (W3C CSS3)).
Because of that modification, browsers support pseudo elements in different syntaxes. Firefox, Opera, Google Chrome and Safari support pseudo elements with two colons and because of backward compatibility, support almost all pseudo elements with one colon also (except the ::selection). Internet Explorer only supports pseudo elements with one colon.
Unfortunately, the use of unknown pseudo elements cause that the browsers ignore the corresponding style declaration block.
So if you want to declare a pseudo element both with one and two colons, you need to duplicate the whole style declaration block.
It is conceivable that Firefox, Opera, Google Chrome and Safari will stop supporting pseudo elements with one colon in the future, but nowadays they support them with one colon also (except the ::selection).
Therefore it is simpler, if you declare the ::after, ::before, ::first-letter, ::first-line pseudos with one colon and the ::selection pseudo with two colons.
Pseudos:
Pseudo | Support | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
::after |
|
Can be used to specify generated content after an element's content. | ||||||||||
::before |
|
Can be used to specify generated content before an element's content. | ||||||||||
::first-letter | Applies to the first letter of an element. | |||||||||||
::first-line | Applies to the first line of an element. | |||||||||||
::selection | Applies to the content that is currently selected or highlighted text by the user. |
Pseudo elements:
::after
Can be used to specify generated content after an element's content.
Note: The ::after pseudo element is supported in Firefox, Opera, Google Chrome and Safari both with one and two colons while in Internet Explorer only with one colon.
Note: The :after pseudo element is supported in Internet Explorer from version 8.
Supported by tags:a, abbr, acronym, address, b, bdo, big, blink, blockQuote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, fieldSet, font, form, H1, H2, H3, H4, H5, H6, html, i, input:button, input:file, input:password, input:reset, input:search, input:submit, input:text, ins, isIndex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plainText, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tt, u, ul, var, xmp
|
||||||||||||||||||
::before
Can be used to specify generated content before an element's content.
Note: The ::before pseudo element is supported in Firefox, Opera, Google Chrome and Safari both with one and two colons while in Internet Explorer only with one colon.
Note: The :before pseudo element is supported in Internet Explorer from version 8.
Supported by tags:a, abbr, acronym, address, b, bdo, big, blink, blockQuote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, fieldSet, font, form, H1, H2, H3, H4, H5, H6, html, i, input:button, input:file, input:password, input:reset, input:search, input:submit, input:text, ins, isIndex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plainText, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tt, u, ul, var, xmp
|
||||||||||||||||||
::first-letter
Applies to the first letter of an element. Can be used as an Initial which is a letter at the beginning of a work that is
larger than the rest of the text.
The ::first-letter pseudo can only be used on block-level elements, or elements with a correspoding 'display:block' style property.
Note: The ::first-letter pseudo element is supported in Firefox, Opera, Google Chrome and Safari both with one and two colons while in Internet Explorer only with one colon.
Supported by tags: |
||||||||||||||||||
::first-line
Applies to the first line of an element.
The ::first-line pseudo can only be used on block-level elements, or elements with correspoding 'display:block' style property.
Note: The ::first-line pseudo element is supported in Firefox, Opera, Google Chrome and Safari both with one and two colons while in Internet Explorer only with one colon.
Supported by tags: |
||||||||||||||||||
::selection
Applies to the content that is currently selected or highlighted text by the user.
Note: The support for the ::selection pseudo element with one colon has been removed in Opera 10 and Safari 4.
Supported by tags:a, abbr, acronym, address, b, bdo, big, blink, blockQuote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, fieldSet, font, form, H1, H2, H3, H4, H5, H6, html, i, input:button, input:file, input:password, input:reset, input:search, input:submit, input:text, ins, isIndex, kbd, label, legend, li, marquee, menu, ol, p, plainText, pre, q, s, samp, select, small, span, strike, strong, sub, sup, table, tBody, td, textArea, tFoot, th, tHead, tt, u, ul, var, xmp
|
User Contributed Comments
This is due to the way browsers construct these elements in the DOM...