/nodeJSstudy/superagent&cheerio pachong/node_modules/cheerio/node_modules/CSSselect/test/tools/docs/W3C_Selectors.html
HTML | 978 lines | 948 code | 22 blank | 8 comment | 0 complexity | 8a46386ecf60270199da0e7325807d7f MD5 | raw file
- <!-- http://www.w3.org/TR/2001/CR-css3-selectors-20011113/ -->
- <html><head><title>Selectors</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <meta http-equiv="Content-Language" content="en">
- <link href="default.css" type="text/css" rel="stylesheet">
- <style type="text/css">
- pre {
- border-right: medium none; padding-right: 0.3cm; border-top: medium none; padding-left: 0.3cm; font-size: 92%; padding-bottom: 0px; margin: 1em 1cm; border-left: medium none; padding-top: 0px; border-bottom: medium none; white-space: pre; background-color: #d5d5d5
- }
- .code {
- font-family: monospace
- }
- table.selectorsReview th {
- background: gray; color: white
- }
- table.selectorsReview th .pattern {
- width: 20%; font-family: monospace
- }
- table.selectorsReview th .meaning {
- width: 45%
- }
- table.selectorsReview tr .described {
- WIDTH: 25%
- }
- table.selectorsReview tr .origin {
- width: 10%; text-align: center
- }
- table.tprofile th.title {
- background: gray; color: white
- }
- table.tprofile th {
- width: 29%
- }
- table.tprofile td {
- width: 71%
- }
- .toc {
- list-style-type: none
- }
- .subtoc ul {
- list-style-type: none
- }
- .subtoc ol {
- list-style-type: none
- }
- .profile {
- margin: 1cm
- }
- .editorNote {
- color: red; font-style: italic
- }
- .e-mail {
- font-size: 90%
- }
- h1 {
- font-size: 200%
- }
- h2 {
- font-size: 170%
- }
- h3 {
- font-size: 150%
- }
- h4 {
- font-size: 130%
- }
- h5 {
- font-size: 120%
- }
- h6 {
- font-size: 110%
- }
- ul.changes {
- font-size: smaller
- }
- table.selectorsReview {
- font-size: smaller; border-collapse: collapse
- }
- .figure {
- text-align: center
- }
- </style>
- <link href="http://www.w3.org/StyleSheets/TR/W3C-CR.css" type="text/css" rel="stylesheet">
- </head>
- <body>
- <div class="head"><p><a href="http://www.w3.org/"><img height="48" alt="W3C" src="http://www.w3.org/Icons/w3c_home" width="72"></a>
- </p><h1><span class="modulename">Selectors</span></h1>
- <h2>W3C Candidate Recommendation 13 November 2001</h2>
- <dl>
- <dt>This version:
- </dt><dd><a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113">
- http://www.w3.org/TR/2001/CR-css3-selectors-20011113</a>
- </dd><dt>Latest version:
- </dt><dd><a href="http://www.w3.org/TR/css3-selectors">
- http://www.w3.org/TR/css3-selectors</a>
- </dd><dt>Previous version:
- </dt><dd><a href="http://www.w3.org/TR/2001/WD-css3-selectors-20010126">
- http://www.w3.org/TR/2001/WD-css3-selectors-20010126</a>
- </dd><dt><a name="editors-list"></a>Editors:
- </dt><dd><a href="mailto:glazman@netscape.com">Daniel Glazman</a> (<span class="company"><a href="http://www.netscape.com/">Netscape/AOL</a></span>)
- </dd><dd><a href="mailto:tantekc@microsoft.com">Tantek Çelik</a> (<span class="company"><a href="http://www.microsoft.com/">Microsoft Corporation</a></span>)
- </dd><dd><a href="mailto:ian@hixie.ch">Ian Hickson</a>
- </dd><dd>Peter Linss (former editor, formerly of <span class="company"><a href="http://www.netscape.com/">Netscape/AOL</a></span>)
- </dd><dd>John Williams (former editor, <span class="company"><a href="http://www.quark.com/">Quark, Inc.</a></span>)
- </dd></dl>
- <p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Copyright">Copyright</a>
- ©2001 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.lcs.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.inria.fr/"><abbr lang="fr" title="Institut National de Recherche en Informatique et Automatique">INRIA</abbr></a>,
- <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#Legal_Disclaimer">liability</a>,
- <a href="http://www.w3.org/Consortium/Legal/ipr-notice-20000612#W3C_Trademarks">trademark</a>,
- <a href="http://www.w3.org/Consortium/Legal/copyright-documents-19990405">document
- use</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-software-19980720">software
- licensing</a> rules apply.
- </p><hr title="Separator for header">
- </div>
- <h2><a name="abstract"></a>Abstract</h2>
- <p><acronym title="Cascading Style Sheets">CSS</acronym> (Cascading Style Sheets) is a language for describing the rendering of
- <acronym title="Hypertext Markup Language">HTML</acronym> and <acronym title="Extensible Markup Language">XML</acronym>
- documents on screen, on paper, in speech, etc. To bind style properties
- to elements in the document, CSS uses <em>selectors,</em> which are patterns
- that match one or more elements. This document describes the selectors that are proposed
- for CSS level 3. It includes and extends the selectors of CSS level 2.
- </p><h2><a name="status"></a>Status of this document</h2>
- <p>This document is one of the "modules" of the upcoming CSS3 specification. It
- not only describes the selectors that already exist in <a href="#CSS1"><abbr title="CSS level 1">CSS1</abbr></a> and <a href="#CSS2"><abbr title="CSS level 2">CSS2</abbr></a>,
- but also proposes new selectors for <abbr title="CSS level 3">CSS3</abbr> as well as for
- other languages that may need them. The CSS Working Group doesn't expect that all
- implementations of CSS3 will have to implement all selectors. Instead,
- there will probably be a small number of variants of CSS3, so-called "profiles".
- For example, it may be that only a profile for non-interactive user agents
- will include all of the proposed selectors.
- </p><p>This specification is being put forth as a <a href="http://www.w3.org/TR/#About">Candidate
- Recommendation</a> by the <a href="http://www.w3.org/Style/Group">CSS Working
- Group</a>. This document is a revision of the <a href="http://www.w3.org/TR/2001/WD-css3-selectors-20010126">Working
- Draft dated 2001 January 26</a>, and has incorporated suggestions received
- during last call review, comments, and further deliberations of the W3C CSS
- Working Group.
- </p><p>The duration of Candidate Recommendation is expected to last approximately
- six months (ending <strong>May, 2002</strong>). All persons are encouraged
- to review and implement this specification and return comments to the (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing
- list <a href="http://www.w3.org/Mail/Lists.html#www-style">www-style</a> (see <a href="http://www.w3.org/Mail/Request">instructions</a>).
- W3C Members can also send comments directly to the CSS Working Group.
- </p><p>Should this specification prove impossible to implement, the Working Group
- will return the document to Working Draft status and make necessary changes.
- Otherwise, the Working Group anticipates asking the W3C Director to advance
- this document to Proposed Recommendation.
- </p><p>This is still a draft document and may be updated, replaced, or obsoleted by
- other documents at any time. It is inappropriate to cite a W3C Candidate Recommendation
- as other than "work in progress." A list of current W3C working drafts
- can be found at <a href="http://www.w3.org/TR">http://www.w3.org/TR</a>.<br>
- <br>
- This document may be available in <a href="http://www.w3.org/Style/css3-selectors-updates/translations">translation</a>.
- The English version of this specification is the only normative version.
- </p><h2><a name="dependencies"></a>Dependencies with other CSS3 Modules</h2>
- <ul>
- <li>General Syntax
- </li><li>Value Assignment, Cascade and Inheritance
- </li><li>Generated Content / Markers
- </li><li>User Interface
- </li></ul>
- <div class="subtoc">
- <h2><a name="contents">Table of contents</a></h2>
- <ul class="toc">
- <li class="tocline2"><a href="#context">1.
- Context</a>
- <ul>
- <li><a href="#changesFromCSS2">1.1
- Changes from CSS2</a> </li></ul>
- </li><li class="tocline2"><a href="#selectors">2.
- Selectors</a>
- </li><li class="tocline2"><a href="#casesens">3.
- Case sensitivity</a>
- </li><li class="tocline2"><a href="#selector-syntax">4. Selector
- syntax</a>
- </li><li class="tocline2"><a href="#grouping">5.
- Groups of selectors</a>
- </li><li class="tocline2"><a href="#simple-selectors">6. Simple
- selectors</a>
- <ul class="toc">
- <li class="tocline3"><a href="#type-selectors">6.1 Type
- selectors</a>
- <ul class="toc">
- <li class="tocline4"><a href="#typenmsp">6.1.1 Type selectors
- and Namespaces</a> </li></ul>
- </li><li class="tocline3"><a href="#universal-selector">6.2 Universal
- selector</a>
- <ul>
- <li><a href="#univnmsp">6.2.1
- Universal selector and Namespaces</a> </li></ul>
- </li><li class="tocline3"><a href="#attribute-selectors">6.3
- Attribute selectors</a>
- <ul class="toc">
- <li class="tocline4"><a href="#attribute-representation">6.3.1
- Representation of attributes and attributes values</a>
- </li><li><a href="#attribute-substrings">6.3.2
- Substring matching attribute selectors</a>
- </li><li class="tocline4"><a href="#attrnmsp">6.3.3 Attribute
- selectors and Namespaces</a>
- </li><li class="tocline4"><a href="#def-values">6.3.4 Default
- attribute values in DTDs</a> </li></ul>
- </li><li class="tocline3"><a href="#class-html">6.4 Class
- selectors</a>
- </li><li class="tocline3"><a href="#id-selectors">6.5 ID
- selectors</a>
- </li><li class="tocline3"><a href="#pseudo-classes">6.6
- Pseudo-classes</a>
- <ul class="toc">
- <li class="tocline4"><a href="#dynamic-pseudos">6.6.1 Dynamic
- pseudo-classes</a>
- </li><li class="tocline4"><a href="#target-pseudo">6.6.2 The
- :target pseudo-class</a>
- </li><li class="tocline4"><a href="#lang-pseudo">6.6.3 The :lang()
- pseudo-class</a>
- </li><li class="tocline4"><a href="#UIstates">6.6.4 UI element
- states pseudo-classes</a>
- </li><li class="tocline4"><a href="#structural-pseudos">6.6.5
- Structural pseudo-classes</a>
- <ul>
- <li><a href="#root-pseudo">:root
- pseudo-class</a>
- </li><li><a href="#nth-child-pseudo">:nth-child()
- pseudo-class</a>
- </li><li><a href="#nth-last-child-pseudo">:nth-last-child()</a>
- </li><li><a href="#nth-of-type-pseudo">:nth-of-type()
- pseudo-class</a>
- </li><li><a href="#nth-last-of-type-pseudo">:nth-last-of-type()</a>
- </li><li><a href="#first-child-pseudo">:first-child
- pseudo-class</a>
- </li><li><a href="#last-child-pseudo">:last-child
- pseudo-class</a>
- </li><li><a href="#first-of-type-pseudo">:first-of-type
- pseudo-class</a>
- </li><li><a href="#last-of-type-pseudo">:last-of-type
- pseudo-class</a>
- </li><li><a href="#only-child-pseudo">:only-child
- pseudo-class</a>
- </li><li><a href="#only-of-type-pseudo">:only-of-type
- pseudo-class</a>
- </li><li><a href="#empty-pseudo">:empty
- pseudo-class</a> </li></ul>
- </li><li class="tocline4"><a href="#content-selectors">6.6.6
- Content pseudo-class</a>
- </li><li><a href="#negation">6.6.7 The
- negation pseudo-class</a> </li></ul></li></ul>
- </li><li><a href="#pseudo-elements">7.
- Pseudo-elements</a>
- <ul>
- <li><a href="#first-line">7.1 The
- :first-line pseudo-element</a>
- </li><li><a href="#first-letter">7.2 The
- :first-letter pseudo-element</a>
- </li><li><a href="#UIfragments">7.3 UI
- element fragments pseudo-elements</a>
- </li><li><a href="#gen-content">7.4 The
- :before and :after pseudo-elements</a> </li></ul>
- </li><li class="tocline2"><a href="#combinators">8. Combinators</a>
- <ul class="toc">
- <li class="tocline3"><a href="#descendant-combinators">8.1
- Descendant combinators</a>
- </li><li class="tocline3"><a href="#child-combinators">8.2 Child
- combinators</a>
- </li><li class="tocline3"><a href="#adjacent-combinators">8.3
- Adjacent sibling combinators</a>
- <ul class="toc">
- <li class="tocline4"><a href="#adjacent-d-combinators">8.3.1
- Adjacent direct combinators</a>
- </li><li class="tocline4"><a href="#adjacent-i-combinators">8.3.2
- Adjacent indirect combinators</a> </li></ul></li></ul>
- </li><li class="tocline2"><a href="#specificity">9. Calculating a
- selector's specificity</a>
- </li><li class="tocline2"><a href="#w3cselgrammar">10. The grammar of
- <span class="modulename">Selectors</span></a>
- <ul class="toc">
- <li class="tocline3"><a href="#grammar">10.1 Grammar</a>
- </li><li class="tocline3"><a href="#lex">10.2
- Lexical scanner</a> </li></ul>
- </li><li class="tocline2"><a href="#downlevel">11. Namespaces and
- Down-Level clients</a>
- </li><li class="tocline2"><a href="#profiling">12. Profiles</a>
- </li><li><a href="#Conformance">13. Conformance
- and Requirements</a>
- </li><li><a href="#Tests">14. Tests</a>
- </li><li><a href="#ACKS">15.
- Acknowledgements</a>
- </li><li class="tocline2"><a href="#references">16. References</a> <!--<li class="tocline2"><a href="#changes">Changes from previous version</a>--></li></ul></div>
- <h2><a name="context">1. Context</a></h2>
- <p>Members of the CSS+FP Working Group proposed during the Clamart meeting to
- modularize the CSS specification.
- </p><p>This modularization, and the externalization of the general syntax of CSS
- will reduce the size of the specification and allow new specifications
- to use selectors and/or CSS general syntax. For instance, behaviors or tree
- transformations.
- </p><p>This specification contains its own <a href="#Tests">test cases</a>, one test per concept introduced in this document.
- These tests are not full conformance tests but are intended to provide users
- with a way to check if a part of this specification is implemented <i>ad minima</i>
- or is not implemented at all.
- </p><h3><a name="changesFromCSS2"></a>1.1 Changes from CSS2</h3>
- <p>The main differences between the selectors in CSS2 and those in
- <span class="modulename">Selectors</span> are:
- </p><ul>
- <li>the list of basic definitions (selector, group of selectors, simple
- selector, etc.) has been clarified
- </li><li>an optional namespace component is now allowed in type element selectors,
- the universal selector and attribute selectors
- </li><li>a new combinator
- </li><li>new simple selectors including substring matching attribute selectors, and new
- pseudo-classes
- </li><li>new pseudo-elements, and introduction of the "::" convention for pseudo-elements
- </li><li>a rewriting of the selectors grammar
- </li><li>profiles to be added to specifications integrating <span class="modulename">Selectors</span> and
- defining the set of selectors which is actually supported by each
- specification
- </li><li><span class="modulename">Selectors</span> are now a CSS3 Module and an independent specification.
- Other specifications can now refer to this document independently of CSS
- </li><li>the specification now contains its own test suite. </li>
- </ul>
- <h2><a name="selectors"></a>2. Selectors</h2>
- <p>A <span class="propernoun">Selector</span> represents a structure. This structure can be used
- as a condition (e.g. in a CSS rule) that determines which elements
- a selector matches in the document tree, or as a flat description of the
- HTML or XML fragment corresponding to that structure.
- </p><p><span class="propernoun">Selectors</span> may range from simple element names to rich contextual
- representations.
- </p><p>The following table summarizes <span class="propernoun">Selector</span> syntax:
- </p><table class="selectorsreview" width="100%" border="1">
- <tbody>
- <tr>
- <th class="pattern">Pattern</th>
- <th class="meaning">Meaning</th>
- <th class="described">Described in section</th>
- <th class="origin">First defined in CSS level</th></tr>
- <tr>
- <td class="pattern">*</td>
- <td class="meaning">any element</td>
- <td class="described"><a href="#universal-selector">Universal
- selector</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E</td>
- <td class="meaning">an element of type E</td>
- <td class="described"><a href="#type-selectors">Type selector</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E[foo]</td>
- <td class="meaning">an E element with a "foo" attribute</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E[foo="bar"]</td>
- <td class="meaning">an E element whose "foo" attribute value is exactly
- equal to "bar"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E[foo~="bar"]</td>
- <td class="meaning">an E element whose "foo" attribute value is a list of
- space-separated values, one of which is exactly equal to "bar"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E[foo^="bar"]</td>
- <td class="meaning">an E element whose "foo" attribute value begins exactly
- with the string "bar"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E[foo$="bar"]</td>
- <td class="meaning">an E element whose "foo" attribute value ends exactly
- with the string "bar"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E[foo*="bar"]</td>
- <td class="meaning">an E element whose "foo" attribute value contains the
- substring "bar"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E[hreflang|="en"]</td>
- <td class="meaning">an E element whose "hreflang" attribute has a hyphen-separated
- list of values beginning (from the left) with "en"</td>
- <td class="described"><a href="#attribute-selectors">Attribute
- selectors</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E:root</td>
- <td class="meaning">an E element, root of the document</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:nth-child(n)</td>
- <td class="meaning">an E element, the n-th child of its parent</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:nth-last-child(n)</td>
- <td class="meaning">an E element, the n-th child of its parent, counting
- from the last one</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:nth-of-type(n)</td>
- <td class="meaning">an E element, the n-th sibling of its type</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:nth-last-of-type(n)</td>
- <td class="meaning">an E element, the n-th sibling of its type, counting
- from the last one</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:first-child</td>
- <td class="meaning">an E element, first child of its parent</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E:last-child</td>
- <td class="meaning">an E element, last child of its parent</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:first-of-type</td>
- <td class="meaning">an E element, first sibling of its type</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:last-of-type</td>
- <td class="meaning">an E element, last sibling of its type</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:only-child</td>
- <td class="meaning">an E element, only child of its parent</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:only-of-type</td>
- <td class="meaning">an E element, only sibling of its type</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:empty</td>
- <td class="meaning">an E element that has no children (including text
- nodes)</td>
- <td class="described"><a href="#structural-pseudos">Structural
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:link <br>E:visited</td>
- <td class="meaning">an E element being the source anchor of a hyperlink of
- which the target is not yet visited (:link) or already visited
- (:visited)</td>
- <td class="described"><a href="#link">The link
- pseudo-classes</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E:active <br>E:hover <br>E:focus</td>
- <td class="meaning">an E element during certain user actions</td>
- <td class="described"><a href="#useraction-pseudos">The user
- action pseudo-classes</a></td>
- <td class="origin">1 and 2</td></tr>
- <tr>
- <td class="pattern">E:target</td>
- <td class="meaning">an E element being the target of the referring URI</td>
- <td class="described"><a href="#target-pseudo">The target
- pseudo-class</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:lang(fr)</td>
- <td class="meaning">an element of type E in language "fr" (the document
- language specifies how language is determined)</td>
- <td class="described"><a href="#lang-pseudo">The :lang()
- pseudo-class </a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E:enabled<br>E:disabled </td>
- <td class="meaning">a user interface element E which is enabled or
- disabled</td>
- <td class="described"><a href="#UIstates">The UI element states
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:checked<br>E:indeterminate </td>
- <td class="meaning">a user interface element E which is checked or in an
- indeterminate state (for instance a radio-button or checkbox)</td>
- <td class="described"><a href="#UIstates">The UI element states
- pseudo-classes</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E:contains("foo")</td>
- <td class="meaning">an E element containing the substring "foo" in its textual
- contents</td>
- <td class="described"><a href="#content-selectors">Content
- pseudo-class</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E::first-line</td>
- <td class="meaning">the first formatted line of an E element</td>
- <td class="described"><a href="#first-line">The :first-line
- pseudo-element</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E::first-letter</td>
- <td class="meaning">the first formatted letter of an E element</td>
- <td class="described"><a href="#first-letter">The :first-letter
- pseudo-element</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E::selection</td>
- <td class="meaning">the portion of an E element that is currently
- selected/highlighted by the user</td>
- <td class="described"><a href="#UIfragments">The UI element
- fragments pseudo-elements</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E::before</td>
- <td class="meaning">generated content before an E element</td>
- <td class="described"><a href="#gen-content">The :before
- pseudo-element</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E::after</td>
- <td class="meaning">generated content after an E element</td>
- <td class="described"><a href="#gen-content">The :after
- pseudo-element</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E.warning</td>
- <td class="meaning">an E element whose class is
- "warning" (the document language specifies how class is determined).</td>
- <td class="described"><a href="#class-html">Class
- selectors</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E#myid</td>
- <td class="meaning">an E element with ID equal to "myid".</td>
- <td class="described"><a href="#id-selectors">ID
- selectors</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E:not(s)</td>
- <td class="meaning">an E element that does not match simple selector s</td>
- <td class="described"><a href="#negation">Negation
- pseudo-class</a></td>
- <td class="origin">3</td></tr>
- <tr>
- <td class="pattern">E F</td>
- <td class="meaning">an F element descendant of an E element</td>
- <td class="described"><a href="#descendant-combinators">Descendant
- combinator</a></td>
- <td class="origin">1</td></tr>
- <tr>
- <td class="pattern">E > F</td>
- <td class="meaning">an F element child of an E element</td>
- <td class="described"><a href="#child-combinators">Child
- combinator</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E + F</td>
- <td class="meaning">an F element immediately preceded by an E element</td>
- <td class="described"><a href="#adjacent-d-combinators">Direct
- adjacent combinator</a></td>
- <td class="origin">2</td></tr>
- <tr>
- <td class="pattern">E ~ F</td>
- <td class="meaning">an F element preceded by an E element</td>
- <td class="described"><a href="#adjacent-i-combinators">Indirect
- adjacent combinator</a></td>
- <td class="origin">3</td></tr></tbody></table>
- <p>The meaning of each selector is derived from the table above by
- prepending "matches" to the contents of each cell of the "Meaning" column.
- </p><h2><a name="casesens">3. Case sensitivity</a></h2>
- <p>The case-sensitivity of document language element names in selectors depends
- on the document language. For example, in HTML, element names are
- case-insensitive, but in XML they are case-sensitive.
- </p><p>The case-sensitivity of attribute names and attribute values in attribute
- selectors also depends on the document language.
- </p><h2><a name="selector-syntax">4. Selector syntax</a></h2>
- <p>A <dfn><a name="selector">selector</a></dfn> is a chain of one or more <a href="#sequence">sequences of simple
- selectors</a> separated by <a href="#combinators">combinators</a>.
- </p><p>A <dfn><a name="sequence">sequence of simple selectors</a></dfn> is a chain
- of <a href="#simple-selectors-dfn">simple selectors</a> that are not separated by a
- <a href="#combinators">combinator</a>. It always begins with a <a href="#type-selectors">type selector</a> or a <a href="#universal-selector">universal
- selector</a>. No other type selector or universal selector is allowed in the
- sequence.
- </p><p>A <dfn><a name="simple-selectors-dfn"></a><a href="#simple-selectors">simple selector</a></dfn> is either a <a href="#type-selectors">type selector</a>, <a href="#universal-selector">universal selector</a>, <a href="#attribute-selectors">attribute selector</a>, <a href="#id-selectors">ID
- selector</a>, <a href="#content-selectors">content selector</a>, or <a href="#pseudo-classes">pseudo-class</a>. One <a href="#pseudo-elements">pseudo-element</a> may be appended to the last sequence
- of simple selectors.
- </p><p><dfn>Combinators</dfn> are: white space, "greater-than sign" (<code>></code>),
- "plus sign" (<code>+</code>) and "tilde" (<code>~</code>).
- White space may appear between a combinator and the simple selectors around
- it. <a name="whitespace"></a>Only the characters "space" (Unicode code 32), "tab"
- (9), "line feed" (10), "carriage return" (13), and "form feed" (12) can occur
- in white space. Other space-like characters, such as "em-space" (8195) and "ideographic
- space" (12288), are never part of white space.
- </p><p>The elements of the document tree represented by a selector are called <dfn><a name="subject"></a>subjects
- of the selector</dfn>. A selector consisting of a single sequence of simple
- selectors represents any element satisfying its requirements. Prepending another
- sequence of simple selectors and a combinator to a sequence imposes additional
- matching constraints, so the subjects of a selector are always a subset of the
- elements represented by the rightmost sequence of simple selectors.
- </p><p><strong><em>Note</em></strong><em>: an empty selector, containing no sequence
- of simple selectors and no combinator, is an <a href="#Conformance">invalid
- selector</a>.</em>
- </p><h2><a name="grouping">5. Groups of selectors</a></h2>
- <p>When several selectors share the same declarations, they may be grouped into
- a comma-separated list.
- </p><div class="example">CSS example(s):
- <p>In this example, we condense three rules with identical declarations into
- one. Thus, </p><pre>h1 { font-family: sans-serif }
- h2 { font-family: sans-serif }
- h3 { font-family: sans-serif }</pre>is equivalent to: <pre>h1, h2, h3 { font-family: sans-serif }</pre></div>
- <p><b>Warning</b>: the equivalence is true in this example because all selectors
- are valid selectors. If just one of these selectors is invalid, the entire group
- of selectors is invalid thus invalidating the rule for all three heading elements,
- whereas only one of the three individual heading rules would be invalid.
-
- </p><h2><a name="simple-selectors">6. Simple selectors</a></h2>
- <h3><a name="type-selectors">6.1 Type selector</a></h3>
- <p>A <dfn>type selector</dfn> is the name of a document language element
- type. A type selector represents an instance of the element type in the document
- tree.
- </p><div class="example">Example:
- <p>The following selector represents an <code>h1</code> element in the document
- tree: </p><pre>h1</pre></div>
- <h4><a name="typenmsp">6.1.1 Type selectors and Namespaces</a></h4>
- <p>Type selectors allow an optional namespace (<a href="#XMLNAMES">[XML-NAMES]</a>) component.
- A namespace prefix that has been previously declared
- may be prepended to the element name separated by the namespace separator
- "vertical bar" (<code>|</code>). The namespace component may be left
- empty to indicate that the selector is only to represent elements with no declared
- namespace. Furthermore, an asterisk may be used for the namespace prefix, indicating
- that the selector represents elements in any namespace (including elements
- with no namespace). Element type selectors that have no namespace component
- (no namespace separator), represent elements without regard
- to the element's namespace (equivalent to "<code>*|</code>") unless a default
- namespace has been declared. In that case, the selector will represent only
- elements in the default namespace.
- </p><p>Note : a type selector containing a namespace prefix that has not been previously
- declared is an <a href="#Conformance">invalid</a> selector.
- The mechanism for declaring a namespace prefix is left up to the language
- implementing <span class="modulename">Selectors</span>.
- In CSS, such a mechanism is defined in the General Syntax module.
- <!--<p>An alternative approach would be to define element type selectors that have
- no namespace component to match only elements that have no namespace (unless
- a default namespace has been declared in the CSS). This would make the selector
- "<code>h1</code>" equivalent to the selector "<code>|h1</code>" as opposed to
- "<code>*|h1</code>". The downside to this approach is that legacy style sheets
- (those written without any namespace constructs) will fail to match in all XML
- documents where namespaces are used throughout, e.g. all XHTML documents. -->
- </p><p>It should be noted that if a namespace prefix used in a selector has not been
- previously declared, then the selector must be considered invalid and the entire
- style rule will be ignored in accordance with the <a href="#Conformance">standard
- error handling rules</a>.
- </p><p>It should further be noted that in a namespace aware client, element type
- selectors will only match against the <a href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local part</a> of the
- element's <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">qualified
- name</a>. See <a href="#downlevel">below</a>
- for notes about matching behaviors in down-level clients.
- </p><p>In summary:
- </p><dl>
- <dt><code>ns|E</code>
- </dt><dd>elements with name E in namespace ns
- </dd><dt><code>*|E</code>
- </dt><dd>elements with name E in any namespace, including those without any
- declared namespace
- </dd><dt><code>|E</code>
- </dt><dd>elements with name E without any declared namespace
- </dd><dt><code>E</code>
- </dt><dd>if no default namespace has been specified, this is equivalent to *|E.
- Otherwise it is equivalent to ns|E where ns is the default namespace. </dd></dl>
- <div class="example">
- <p>CSS examples:
- </p><pre>@namespace foo url(http://www.example.com);
- foo|h1 { color: blue }
- foo|* { color: yellow }
- |h1 { color: red }
- *|h1 { color: green }
- h1 { color: green }</pre>
- <p>The first rule will match only <code>h1</code> elements in the "http://www.example.com"
- namespace.
- </p><p>The second rule will match all elements in the "http://www.example.com" namespace.
-
- </p><p>The third rule will match only <code>h1</code> elements without any declared
- namespace.
- </p><p>The fourth rule will match <code>h1</code> elements in any namespace (including
- those without any declared namespace).
- </p><p>The last rule is equivalent to the fourth rule because no default namespace
- has been defined.</p></div>
- <h3><a name="universal-selector">6.2 Universal selector</a> </h3>
- <p>The <dfn>universal selector</dfn>, written "asterisk" (<code>*</code>),
- represents the qualified name of any element type. It represents then any single
- element in the document tree in any namespace (including those without any declared
- namespace) if no default namespace has been specified. If a default namespace
- has been specified, see <a href="#univnmsp">Universal selector and Namespaces</a> below.
- </p><p>If the universal selector is not the only component of a sequence of simple
- selectors, the <code>*</code> may be omitted. For example:
- </p><div class="example">
- <ul>
- <li><code>*[hreflang|=en]</code> and <code>[hreflang|=en]</code> are equivalent,
- </li><li><code>*.warning</code> and <code>.warning</code> are equivalent,
- </li><li><code>*#myid</code> and <code>#myid</code> are equivalent. </li></ul></div>
- <p><b>Note</b>: it is recommended that the <code>*</code>, representing the
- universal selector, not be omitted.
- </p><h4><a name="univnmsp">6.2.1 Universal selector and Namespaces</a></h4>
- <p>The universal selector allows an optional namespace component.
- </p><dl>
- <dt><code>ns|*</code>
- </dt><dd>all elements in namespace ns
- </dd><dt><code>*|*</code>
- </dt><dd>all elements
- </dd><dt><code>|*</code>
- </dt><dd>all elements without any declared namespace
- </dd><dt><code>*</code>
- </dt><dd>if no default namespace has been specified, this is equivalent to *|*.
- Otherwise it is equivalent to ns|* where ns is the default namespace. </dd></dl>
- <p>Note: a universal selector containing a namespace prefix that has not been
- previously declared is an <a href="#Conformance">invalid</a> selector.
- The mechanism for declaring a namespace prefix is left up to the language
- implementing <span class="modulename">Selectors</span>.
- In CSS, such a mechanism is defined in the General Syntax module.
- </p><h3><a name="attribute-selectors">6.3 Attribute selectors</a></h3>
- <p><span class="propernoun">Selectors</span> allow the representation of an element's attributes.
- </p><h4><a name="attribute-representation">6.3.1 Attribute presence and values
- selectors</a></h4>
- <p>CSS2 introduced four attribute selectors:
- </p><dl>
- <dt><code>[att]</code>
- </dt><dd>Represents the <code>att</code> attribute, whatever the value of the
- attribute.
- </dd><dt><code>[att=val]</code>
- </dt><dd>Represents the <code>att</code> attribute with value exactly "val".
- </dd><dt><code>[att~=val]</code>
- </dt><dd>Represents the <code>att</code> attribute whose value is a space-separated list of words,
- one of which is exactly "val". If this selector is used, the
- words in the value must not contain spaces (since they are separated by
- spaces).
- </dd><dt><code>[att|=val]</code>
- </dt><dd>Represents the <code>att</code> attribute, its value either being exactly "val" or
- beginning with "val" immediately followed by "-".
- This is primarily intended to allow language subcode matches
- (e.g., the <code>hreflang</code> attribute on the <code>link</code> element in HTML)
- as described in RFC 3066 (<a class="noxref" href="#rfc3066" rel="biblioentry">[RFC3066]</a>).
- Note: for <code>lang</code> (or <code>xml:lang</code>) language subcode matching,
- please see <a href="#lang-pseudo">the <code>:lang</code> pseudo-class</a>.
-
- </dd></dl>
- <p>Attribute values must be identifiers or strings. The case-sensitivity of
- attribute names and values in selectors depends on the document language.
- </p><div class="example">Examples:
- <p>For example, the following attribute selector represents an <code>h1</code>
- element that carries the <code>title</code> attribute, whatever its value: </p><pre>h1[title]</pre>
- <p>In the following example, the selector represents a <code>span</code> element
- whose <code>class</code> attribute has exactly the value "example": </p><pre>span[class=example]</pre>
- Multiple attribute selectors can be used to represent several attributes of
- an element, or several conditions on the same attribute.
- <p>Here, the selector represents a <code>span</code> element whose <code>hello</code>
- attribute has exactly the value "Cleveland" and whose <code>goodbye</code> attribute
- has exactly the value "Columbus": </p><pre>span[hello="Cleveland"][goodbye="Columbus"]</pre>
- <p>The following selectors illustrate the differences between "=" and "~=".
- The first selector will represent, for example, the value "copyright copyleft
- copyeditor" on a <code>rel</code> attribute. The second selector will only
- represent an <code>a</code> element with an <code>href</code> attribute having
- the exact value "http://www.w3.org/".
- </p><pre>a[rel~="copyright"]
- a[href="http://www.w3.org/"]</pre>
- <p>The following selector represents a <code>link</code> element whose
- <code>hreflang</code> attribute is exactly "fr".
- </p><pre>link[hreflang=fr]</pre>
- <p>The following selector represents a <code>link</code> element for which the
- values of the <code>hreflang</code> attribute begins with "en", including
- "en", "en-US", and "en-cockney":
- </p><pre>link[hreflang|="en"]</pre>
- <p>Similarly, the following selectors represents a <code>DIALOGUE</code> element
- whenever it has one of two different values for an attribute <code>character</code>:
- </p><pre>DIALOGUE[character=romeo]
- DIALOGUE[character=juliet]</pre></div>
- <h4><a name="attribute-substrings"></a>6.3.2 Substring matching attribute
- selectors</h4>
- <p>Three additional attribute selectors are provided
- for matching substrings in the value of an attribute:
- </p><dl>
- <dt><code>[att^=val]</code>
- </dt><dd>Represents the <code>att</code> attribute whose value begins with
- the prefix "val"
- </dd><dt><code>[att$=val]</code>
- </dt><dd>Represents the <code>att</code> attribute whose value ends with the
- suffix "val"
- </dd><dt><code>[att*=val]</code>
- </dt><dd>Represents the <code>att</code> attribute whose value contains at least
- one instance of the substring "val" </dd></dl>
- <p>Attribute values must be identifiers or strings. The case-sensitivity of
- attribute names in selectors depends on the document language.
- </p><p>Example:
- </p><p>The following selector represents an HTML <code>object</code>, referencing an
- image:</p><pre>object[type^="image/"]
- </pre>
- <p>The following selector represents an HTML anchor <code>a</code> with an
- <code>href</code> attribute whose value ends with ".html".
- </p><pre>a[href$=".html"]</pre>
- <p>The following selector represents a HTML paragraph with a <code>title</code>
- attribute whose value contains the substring "hello"</p><pre>p[title*="hello"] </pre>
- <h4><a name="attrnmsp">6.3.3 Attribute selectors and Namespaces</a></h4>
- <p>Attribute selectors allow an optional namespace component to the attribute
- name. A namespace prefix that has been previously declared may be prepended
- to the attribute name separated by the namespace separator
- "vertical bar" (<code>|</code>). In keeping with the Namespaces in
- the XML recommendation, default namespaces do not apply to attributes, therefore
- attribute selectors without a namespace component apply only to attributes that
- have no declared namespace (equivalent to "<code>|attr</code>"). An asterisk
- may be used for the namespace prefix indicating that the selector is to match
- all attribute names without regard to the attribute's namespace.
- </p><p>Note : an attribute
- selector with an attribute name containing a namespace prefix that has
- not been previously declared is an <a href="#Conformance">invalid</a> selector.
- The mechanism for declaring a namespace prefix is left up to the language
- implementing <span class="modulename">Selectors</span>.
- In CSS, such a mechanism is defined in the General Syntax module.
- </p><p>CSS examples:
- </p><div class="example">
- <pre>@namespace foo "http://www.example.com";
- [foo|att=val] { color: blue }
- [*|att] { color: yellow }
- [|att] { color: green }
- [att] { color: green }</pre>
- The first rule will match only elements with the attribute <code>att</code>
- in the "http://www.example.com" namespace with the value "val".
- <p>The second rule will match only elements with the attribute <code>att</code>
- regardless of the namespace of the attribute (including no declared namespace).
- </p><p>The last two rules are equivalent and will match only elements with the
- attribute <code>att</code> where the attribute is not declared to be in a
- namespace.</p></div>
- <h4><a name="def-values">6.3.4 Default attribute values in DTDs</a></h4>
- <p>Attribute selectors represent explicitly set attribute values in the document
- tree. Default attribute values may be defined in a DTD or elsewhere.
- <span class="propernoun">Selectors</span> should be designed so that they work
- even if the default values are not included in the document tree.
- </p><div class="example">Examples:
- <p>For example, consider an element <code>EXAMPLE</code> with an attribute
- <code>notation</code> that has a default value of "decimal". The DTD fragment
- might be </p><pre><!ATTLIST EXAMPLE notation (decimal,octal) "decimal"></pre>
- If the selectors represent an <code>EXAMPLE</code> element when the value of
- the attribute is explicitly set:
- <pre>EXAMPLE[notation=decimal]
- EXAMPLE[notation=octal]</pre>
- then to represent only the case where this attribute is set by default, and
- not explicitly, the following selector might be used:
- <pre>EXAMPLE:not([notation])</pre>
- </div>
- <h3><a name="class-html">6.4 Class selectors</a></h3>
- <p>Working with HTML, authors may use the period (<code>.</code>) notation as
- an alternative to the <code>~=</code> notation when representing the <code>class</code>
- attribute. Thus, for HTML, <code>div.value</code> and <code>div[class~=value]</code>
- have the same meaning. The attribute value must immediately follow the "period"
- (<code>.</code>). Note: UAs may apply selectors using the period (.) notation
- in XML documents if the UA has namespace specific knowledge that allows it to
- determine which attribute is the "class" attribute for the respective
- namespace. One such example of namespace specific knowledge is the prose in
- the specification for a particular namespace (e.g. SVG 1.0 [<a href="#SVG">SVG</a>]
- describes the <a href="http://www.w3.org/TR/2001/PR-SVG-20010719/styling.html#ClassAttribute">SVG
- "class" attribute</a> and how a UA should interpret it, and similarly
- MathML 1.01 [<a href="#MATH">MATH</a>] describes the <a href="http://www.w3.org/1999/07/REC-MathML-19990707/chapter2.html#sec2.3.4">MathML
- "class" attribute</a>.)
- </p><p>
- </p><div class="example">Examples:
- <p>For example, we can represent an arbitrary element with
- <code>class~="pastoral"</code> as follows: </p><pre>*.pastoral</pre>or just <pre>.pastoral</pre>
- The following selector represents an <code>h1</code> element with <code>class~="pastoral"</code>:
- <pre>h1.pastoral</pre>
- <p>For example, the following selector represents a <code>p</code> element whose
- <code>class</code> attribute has been assigned a list of space-separated values that
- includes "pastoral" and "marine": </p><pre>p.pastoral.marine</pre>
- <p>It is fully identical to:</p><pre>p.marine.pastoral</pre>
- <p>This selector represents for example a <code>p</code> with <code>class="pastoral
- blue aqua marine"</code> or <code>class="marine blue pastoral aqua" </code>but
- not <code>class="pastoral blue"</code>.
- </p></div>
- <h3><a name="id-selectors">6.5 ID selectors</a></h3>
- <p>Document languages may contain attributes that are declared to be of type ID.
- What makes attributes of type ID special is that no two such attributes can
- have the same value in a document, regardless of the type of the elements that
- carry them; whatever the document language, an ID typed attribute can be used
- to uniquely identify its element. In HTML all ID attributes are named "id";
- XML applications may name ID attributes differently, but the same restriction
- applies.
- </p><p>An ID typed attribute of a document language allows authors to assign an identifier
- to one element instance in the document tree. W3C ID selectors represent an
- element instance based on its identifier. An ID selector contains a "number
- sign" (#) immediately followed by the ID value.
- </p><div class="example">Examples:
- <p>The following ID selector represents an <code>h1</code> element whose ID typed
- attribute has the value "chapter1":
- </p><pre>h1#chapter1</pre>
- <p>The following ID selector represents any element whose ID typed attribute
- has the value "chapter1":
- </p><pre>#chapter1</pre>
- The following selector represents any element whose ID typed attribute has the
- value "z98y".
- <pre>*#z98y</pre></div>
- <div class="note"><i><b>Note.</b> In XML 1.0 <a class="noxref" href="http://www.w3.org/TR/REC-CSS2/refs.html#ref-XML10" rel="biblioentry">[XML10]</a>, the information about which attribute contains an
- element's IDs is contained in a DTD or a schema. When parsing XML, UAs do not
- always read the DTD, and thus may not know what the ID of an element is
- (though a UA may have namespace specific knowledge that allows it to determine
- which attribute is the ID attribute for that namespace). If
- a style sheet designer knows or suspects that a UA may not know what the ID of an
- element is, he should use normal attribute selectors instead:
- <code>[name=p371]</code> instead of <code>#p371</code>.
- Elements in XML 1.0 documents without a DTD do not have IDs at all.</i></div>
- <h3><a name="pseudo-classes">6.6 Pseudo-classes</a></h3>
- <p>The pseudo-class concept is introduced to permit selection based on information
- that lies outside of the document tree or that cannot be expressed using the
- other simple selectors.
- </p><p>A pseudo-class always contains a "colon" (<code>:</code>) followed
- by the name of the pseudo-class and optionally by a value between parentheses.
- </p><p>Pseudo-classes are allowed in all sequences of simple selectors contained in
- a selector. Pseudo-classes are allowed anywhere in sequences of simple selectors,
- after the leading type selector or universal selector (possibly omitted). Pseudo-class
- names are case-insensitive. Some pseudo-classes are mutually exclusive, while
- others can be applied simultaneously to the same element. Pseudo-classes may
- be dynamic, in the sense that an element may acquire or lose a pseudo-class
- while a user interacts with the document.
- </p><h4><a name="dynamic-pseudos">6.6.1 Dynamic pseudo-classes</a></h4>
- <p>Dynamic pseudo-classes classify elements on characteristics other than their
- name, attributes or content, in principle characteristics that cannot be deduced
- from the document tree.
- </p><p>Dynamic pseudo-classes do not appear in the document source or document tree.
- </p><h5>The <a name="link">link pseudo-classes: :link and :visited</a></h5>
- <p>User agents commonly display unvisited links differently from previously
- visited ones. <span class="modulename">Selectors</span> provides the pseudo-classes <code>:link</code> and
- <code>:visited</code> to distinguish them:
- </p><ul>
- <li>The <code>:link</code> pseudo-class applies for links that have not yet been
- visited.
- </li><li>The <code>:visited</code> pseudo-class applies once the link has been visited
- by the user. </li></ul>
- <div class="note"><i><b>Note.</b> After some amount of time, user agents may
- choose to return a visited link to the (unvisited) ':link' state.</i></div>
- <p>The two states are mutually exclusive.
- </p><div class="example">Example:
- <p>The following selector represents links carrying class <code>external</code> and
- already visited: </p><pre>a.exte