Other CSS 2.1 pseudoclasses
In addition to the anchor pseudo-classes, the CSS 2 specification introduced additional pseudoclass selectors. Be warned, however, that they are not well supported at this time.
-
:focus This targets elements that have focus, such as a form element that is highlighted and accepting user input. Although CSS 2 permits
:focusto be applied to any element, it is currently only supported for use with the form elements. Netscape 6 supports:focuswitha,input,textarea, andselect.Example:
input:focus {background-color: yellow;}-
:first-child This targets an element that is the first occurring child of a parent element. It allows you to select the first paragraph of a
divor the firstliin aul, for example.Example:
li:first-child {font-weight: bold;}-
:lang( ) This targets an element that targets elements for which a language has been specified. It functions the same as the
lang|=attribute selector, but may be more robust.Example:
p:lang(de) {color: green;}
Warning
Browser alert: Internet Explorer for Windows does not support
:focus or :first-child in Versions 6 and earlier.
Support in IE 7 (in beta as of this writing) is undocumented.
Internet Explorer 5 for Macintosh, Netscape 6+ and Opera 7+ do
support them. Internet Explorer 5 for Macintosh is the only browser
that supports the :lang
pseudoclass as of this writing.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access