Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/test/data/dromaeo/tests/jslib-traverse-jquery.html

Issue 269054: Importing dromaeo performance tests to src/chrome/test/data.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../htmlrunner.js"></script>
4 <script src="../lib/jquery.js"></script>
5 <script>
6 window.onload = function(){
7 startTest("jslib-traverse-jquery", '');
8
9 // Try to force real results
10 var ret, tmp, div, dd;
11
12 var html = document.body.innerHTML;
13
14 prep(function(){
15 div = jQuery("div");
16 dd = jQuery("dd");
17 var tmp = document.createElement("div");
18 tmp.innerHTML = html;
19 document.body.appendChild( tmp );
20 });
21
22 test("jQuery - parent x10", function(){
23 for ( var i = 0; i < 100; i++ )
24 ret = div.parent().length;
25 });
26
27 test("jQuery - parents x10", function(){
28 for ( var i = 0; i < 100; i++ )
29 ret = div.parents().length;
30 });
31
32 test("jQuery - prev x10", function(){
33 for ( var i = 0; i < 100; i++ )
34 ret = div.prev().length;
35 });
36
37 test("jQuery - prevAll", function(){
38 for ( var i = 0; i < 10; i++ )
39 ret = dd.prevAll().length;
40 });
41
42 test("jQuery - next x10", function(){
43 for ( var i = 0; i < 100; i++ )
44 ret = div.next().length;
45 });
46
47 test("jQuery - nextAll", function(){
48 for ( var i = 0; i < 10; i++ )
49 ret = dd.nextAll().length;
50 });
51
52 test("jQuery - siblings", function(){
53 for ( var i = 0; i < 10; i++ )
54 ret = dd.siblings().length;
55 });
56
57 test("jQuery - children", function(){
58 for ( var i = 0; i < 10; i++ )
59 ret = div.children().length;
60 });
61
62 endTest();
63 };
64 </script>
65 </head>
66 <body>
67 <div class="head">
68 <p><a href="http://www.w3.org/"><img height=48 alt=W3C src="http://www.w3.org /Icons/w3c_home" width=72></a>
69
70 <h1 id="title">Selectors</h1>
71
72 <h2>W3C Working Draft 15 December 2005</h2>
73
74 <dl>
75
76 <dt>This version:
77
78 <dd><a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215">
79 http://www.w3.org/TR/2005/WD-css3-selectors-20051215</a>
80
81 <dt>Latest version:
82
83 <dd><a href="http://www.w3.org/TR/css3-selectors">
84 http://www.w3.org/TR/css3-selectors</a>
85
86 <dt>Previous version:
87
88 <dd><a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113">
89 http://www.w3.org/TR/2001/CR-css3-selectors-20011113</a>
90
91 <dt><a name=editors-list></a>Editors:
92
93 <dd class="vcard"><span class="fn">Daniel Glazman</span> (Invited Expert)</d d>
94
95 <dd class="vcard"><a lang="tr" class="url fn" href="http://www.tantek.com/"> Tantek &Ccedil;elik</a> (Invited Expert)
96
97 <dd class="vcard"><a href="mailto:ian@hixie.ch" class="url fn">Ian Hickson</ a> (<span
98 class="company"><a href="http://www.google.com/">Google</a></span>)
99
100 <dd class="vcard"><span class="fn">Peter Linss</span> (former editor, <span class="company"><a
101 href="http://www.netscape.com/">Netscape/AOL</a></span>)
102
103 <dd class="vcard"><span class="fn">John Williams</span> (former editor, <spa n class="company"><a
104 href="http://www.quark.com/">Quark, Inc.</a></span>)
105
106 </dl>
107
108 <p class="copyright"><a
109 href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">
110 Copyright</a> &copy; 2005 <a href="http://www.w3.org/"><abbr
111 title="World Wide Web Consortium">W3C</abbr></a><sup>&reg;</sup>
112 (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts
113 Institute of Technology">MIT</abbr></a>, <a
114 href="http://www.ercim.org/"><acronym title="European Research
115 Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a
116 href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
117 <a
118 href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liabili ty</a>,
119 <a
120 href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark </a>,
121 <a
122 href="http://www.w3.org/Consortium/Legal/copyright-documents">document
123 use</a> rules apply.
124
125 <hr title="Separator for header">
126
127 </div>
128
129 <h2><a name=abstract></a>Abstract</h2>
130
131 <p><em>Selectors</em> are patterns that match against elements in a
132 tree. Selectors have been optimized for use with HTML and XML, and
133 are designed to be usable in performance-critical code.</p>
134
135 <p><acronym title="Cascading Style Sheets">CSS</acronym> (Cascading
136 Style Sheets) is a language for describing the rendering of <acronym
137 title="Hypertext Markup Language">HTML</acronym> and <acronym
138 title="Extensible Markup Language">XML</acronym> documents on
139 screen, on paper, in speech, etc. CSS uses Selectors for binding
140 style properties to elements in the document. This document
141 describes extensions to the selectors defined in CSS level 2. These
142 extended selectors will be used by CSS level 3.
143
144 <p>Selectors define the following function:</p>
145
146 <pre>expression &#x2217; element &rarr; boolean</pre>
147
148 <p>That is, given an element and a selector, this specification
149 defines whether that element matches the selector.</p>
150
151 <p>These expressions can also be used, for instance, to select a set
152 of elements, or a single element from a set of elements, by
153 evaluating the expression across all the elements in a
154 subtree. <acronym title="Simple Tree Transformation
155 Sheets">STTS</acronym> (Simple Tree Transformation Sheets), a
156 language for transforming XML trees, uses this mechanism. <a href="#refsSTTS"> [STTS]</a></p>
157
158 <h2><a name=status></a>Status of this document</h2>
159
160 <p><em>This section describes the status of this document at the
161 time of its publication. Other documents may supersede this
162 document. A list of current W3C publications and the latest revision
163 of this technical report can be found in the <a
164 href="http://www.w3.org/TR/">W3C technical reports index at
165 http://www.w3.org/TR/.</a></em></p>
166
167 <p>This document describes the selectors that already exist in <a
168 href="#refsCSS1"><abbr title="CSS level 1">CSS1</abbr></a> and <a
169 href="#refsCSS21"><abbr title="CSS level 2">CSS2</abbr></a>, and
170 also proposes new selectors for <abbr title="CSS level
171 3">CSS3</abbr> and other languages that may need them.</p>
172
173 <p>The CSS Working Group doesn't expect that all implementations of
174 CSS3 will have to implement all selectors. Instead, there will
175 probably be a small number of variants of CSS3, called profiles. For
176 example, it may be that only a profile for interactive user agents
177 will include all of the selectors.</p>
178
179 <p>This specification is a last call working draft for the the <a
180 href="http://www.w3.org/Style/CSS/members">CSS Working Group</a>
181 (<a href="/Style/">Style Activity</a>). This
182 document is a revision of the <a
183 href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/">Candidate
184 Recommendation dated 2001 November 13</a>, and has incorporated
185 implementation feedback received in the past few years. It is
186 expected that this last call will proceed straight to Proposed
187 Recommendation stage since it is believed that interoperability will
188 be demonstrable.</p>
189
190 <p>All persons are encouraged to review and implement this
191 specification and return comments to the (<a
192 href="http://lists.w3.org/Archives/Public/www-style/">archived</a>)
193 public mailing list <a
194 href="http://www.w3.org/Mail/Lists.html#www-style">www-style</a>
195 (see <a href="http://www.w3.org/Mail/Request">instructions</a>). W3C
196 Members can also send comments directly to the CSS Working
197 Group.
198 The deadline for comments is 14 January 2006.</p>
199
200 <p>This is still a draft document and may be updated, replaced, or
201 obsoleted by other documents at any time. It is inappropriate to
202 cite a W3C Working Draft as other than &quot;work in progress&quot;.
203
204 <p>This document may be available in <a
205 href="http://www.w3.org/Style/css3-selectors-updates/translations">translation </a>.
206 The English version of this specification is the only normative
207 version.
208
209 <div class="subtoc">
210
211 <h2 id="test10"><a name=contents>Table of contents</a></h2>
212
213 <ul class="toc">
214 <li class="tocline2"><a href="#context">1. Introduction</a>
215 <ul>
216 <li><a href="#dependencies">1.1. Dependencies</a> </li>
217 <li><a href="#terminology">1.2. Terminology</a> </li>
218 <li><a href="#changesFromCSS2">1.3. Changes from CSS2</a> </li>
219 </ul>
220 <li class="tocline2"><a href="#selectors">2. Selectors</a>
221 <li class="tocline2"><a href="#casesens">3. Case sensitivity</a>
222 <li class="tocline2"><a href="#selector-syntax">4. Selector syntax</a>
223 <li class="tocline2"><a href="#grouping">5. Groups of selectors</a>
224 <li class="tocline2"><a href="#simple-selectors">6. Simple selectors</a>
225 <ul class="toc">
226 <li class="tocline3"><a href="#type-selectors">6.1. Type selectors</a>
227 <ul class="toc">
228 <li class="tocline4"><a href="#typenmsp">6.1.1. Type selectors and names paces</a></li>
229 </ul>
230 <li class="tocline3"><a href="#universal-selector">6.2. Universal selector </a>
231 <ul>
232 <li><a href="#univnmsp">6.2.1. Universal selector and namespaces</a></li >
233 </ul>
234 <li class="tocline3"><a href="#attribute-selectors">6.3. Attribute selecto rs</a>
235 <ul class="toc">
236 <li class="tocline4"><a href="#attribute-representation">6.3.1. Represen tation of attributes and attributes values</a>
237 <li><a href="#attribute-substrings">6.3.2. Substring matching attribute selectors</a>
238 <li class="tocline4"><a href="#attrnmsp">6.3.3. Attribute selectors and namespaces</a>
239 <li class="tocline4"><a href="#def-values">6.3.4. Default attribute valu es in DTDs</a></li>
240 </ul>
241 <li class="tocline3"><a href="#class-html">6.4. Class selectors</a>
242 <li class="tocline3"><a href="#id-selectors">6.5. ID selectors</a>
243 <li class="tocline3"><a href="#pseudo-classes">6.6. Pseudo-classes</a>
244 <ul class="toc">
245 <li class="tocline4"><a href="#dynamic-pseudos">6.6.1. Dynamic pseudo-cl asses</a>
246 <li class="tocline4"><a href="#target-pseudo">6.6.2. The :target pseudo- class</a>
247 <li class="tocline4"><a href="#lang-pseudo">6.6.3. The :lang() pseudo-cl ass</a>
248 <li class="tocline4"><a href="#UIstates">6.6.4. UI element states pseudo -classes</a>
249 <li class="tocline4"><a href="#structural-pseudos">6.6.5. Structural pse udo-classes</a>
250 <ul>
251 <li><a href="#root-pseudo">:root pseudo-class</a>
252 <li><a href="#nth-child-pseudo">:nth-child() pseudo-class</a>
253 <li><a href="#nth-last-child-pseudo">:nth-last-child()</a>
254 <li><a href="#nth-of-type-pseudo">:nth-of-type() pseudo-class</a>
255 <li><a href="#nth-last-of-type-pseudo">:nth-last-of-type()</a>
256 <li><a href="#first-child-pseudo">:first-child pseudo-class</a>
257 <li><a href="#last-child-pseudo">:last-child pseudo-class</a>
258 <li><a href="#first-of-type-pseudo">:first-of-type pseudo-class</a>
259 <li><a href="#last-of-type-pseudo">:last-of-type pseudo-class</a>
260 <li><a href="#only-child-pseudo">:only-child pseudo-class</a>
261 <li><a href="#only-of-type-pseudo">:only-of-type pseudo-class</a>
262 <li><a href="#empty-pseudo">:empty pseudo-class</a></li>
263 </ul>
264 <li class="tocline4"><a href="#negation">6.6.7. The negation pseudo-clas s</a></li>
265 </ul>
266 </li>
267 </ul>
268 <li><a href="#pseudo-elements">7. Pseudo-elements</a>
269 <ul>
270 <li><a href="#first-line">7.1. The ::first-line pseudo-element</a>
271 <li><a href="#first-letter">7.2. The ::first-letter pseudo-element</a>
272 <li><a href="#UIfragments">7.3. The ::selection pseudo-element</a>
273 <li><a href="#gen-content">7.4. The ::before and ::after pseudo-elements</ a></li>
274 </ul>
275 <li class="tocline2"><a href="#combinators">8. Combinators</a>
276 <ul class="toc">
277 <li class="tocline3"><a href="#descendant-combinators">8.1. Descendant com binators</a>
278 <li class="tocline3"><a href="#child-combinators">8.2. Child combinators</ a>
279 <li class="tocline3"><a href="#sibling-combinators">8.3. Sibling combinato rs</a>
280 <ul class="toc">
281 <li class="tocline4"><a href="#adjacent-sibling-combinators">8.3.1. Adja cent sibling combinator</a>
282 <li class="tocline4"><a href="#general-sibling-combinators">8.3.2. Gener al sibling combinator</a></li>
283 </ul>
284 </li>
285 </ul>
286 <li class="tocline2"><a href="#specificity">9. Calculating a selector's spec ificity</a>
287 <li class="tocline2"><a href="#w3cselgrammar">10. The grammar of Selectors</ a>
288 <ul class="toc">
289 <li class="tocline3"><a href="#grammar">10.1. Grammar</a>
290 <li class="tocline3"><a href="#lex">10.2. Lexical scanner</a></li>
291 </ul>
292 <li class="tocline2"><a href="#downlevel">11. Namespaces and down-level clie nts</a>
293 <li class="tocline2"><a href="#profiling">12. Profiles</a>
294 <li><a href="#Conformance">13. Conformance and requirements</a>
295 <li><a href="#Tests">14. Tests</a>
296 <li><a href="#ACKS">15. Acknowledgements</a>
297 <li class="tocline2"><a href="#references">16. References</a>
298 </ul>
299
300 </div>
301
302 <h2><a name=context>1. Introduction</a></h2>
303
304 <h3><a name=dependencies></a>1.1. Dependencies</h3>
305
306 <p>Some features of this specification are specific to CSS, or have
307 particular limitations or rules specific to CSS. In this
308 specification, these have been described in terms of CSS2.1. <a
309 href="#refsCSS21">[CSS21]</a></p>
310
311 <h3><a name=terminology></a>1.2. Terminology</h3>
312
313 <p>All of the text of this specification is normative except
314 examples, notes, and sections explicitly marked as
315 non-normative.</p>
316
317 <h3><a name=changesFromCSS2></a>1.3. Changes from CSS2</h3>
318
319 <p><em>This section is non-normative.</em></p>
320
321 <p>The main differences between the selectors in CSS2 and those in
322 Selectors are:
323
324 <ul>
325
326 <li>the list of basic definitions (selector, group of selectors,
327 simple selector, etc.) has been changed; in particular, what was
328 referred to in CSS2 as a simple selector is now called a sequence
329 of simple selectors, and the term "simple selector" is now used for
330 the components of this sequence</li>
331
332 <li>an optional namespace component is now allowed in type element
333 selectors, the universal selector and attribute selectors</li>
334
335 <li>a <a href="#general-sibling-combinators">new combinator</a> has been intr oduced</li>
336
337 <li>new simple selectors including substring matching attribute
338 selectors, and new pseudo-classes</li>
339
340 <li>new pseudo-elements, and introduction of the "::" convention
341 for pseudo-elements</li>
342
343 <li>the grammar has been rewritten</li>
344
345 <li>profiles to be added to specifications integrating Selectors
346 and defining the set of selectors which is actually supported by
347 each specification</li>
348
349 <li>Selectors are now a CSS3 Module and an independent
350 specification; other specifications can now refer to this document
351 independently of CSS</li>
352
353 <li>the specification now has its own test suite</li>
354
355 </ul>
356
357 <h2><a name=selectors></a>2. Selectors</h2>
358
359 <p><em>This section is non-normative, as it merely summarizes the
360 following sections.</em></p>
361
362 <p>A Selector represents a structure. This structure can be used as a
363 condition (e.g. in a CSS rule) that determines which elements a
364 selector matches in the document tree, or as a flat description of the
365 HTML or XML fragment corresponding to that structure.</p>
366
367 <p>Selectors may range from simple element names to rich contextual
368 representations.</p>
369
370 <p>The following table summarizes the Selector syntax:</p>
371
372 <table class="selectorsReview">
373 <thead>
374 <tr>
375 <th class="pattern">Pattern</th>
376 <th class="meaning">Meaning</th>
377 <th class="described">Described in section</th>
378 <th class="origin">First defined in CSS level</th></tr>
379 <tbody>
380 <tr>
381 <td class="pattern">*</td>
382 <td class="meaning">any element</td>
383 <td class="described"><a
384 href="#universal-selector">Universal
385 selector</a></td>
386 <td class="origin">2</td></tr>
387 <tr>
388 <td class="pattern">E</td>
389 <td class="meaning">an element of type E</td>
390 <td class="described"><a
391 href="#type-selectors">Type selector</a></td>
392 <td class="origin">1</td></tr>
393 <tr>
394 <td class="pattern">E[foo]</td>
395 <td class="meaning">an E element with a "foo" attribute</td>
396 <td class="described"><a
397 href="#attribute-selectors">Attribute
398 selectors</a></td>
399 <td class="origin">2</td></tr>
400 <tr>
401 <td class="pattern">E[foo="bar"]</td>
402 <td class="meaning">an E element whose "foo" attribute value is exactly
403 equal to "bar"</td>
404 <td class="described"><a
405 href="#attribute-selectors">Attribute
406 selectors</a></td>
407 <td class="origin">2</td></tr>
408 <tr>
409 <td class="pattern">E[foo~="bar"]</td>
410 <td class="meaning">an E element whose "foo" attribute value is a list of
411 space-separated values, one of which is exactly equal to "bar"</td>
412 <td class="described"><a
413 href="#attribute-selectors">Attribute
414 selectors</a></td>
415 <td class="origin">2</td></tr>
416 <tr>
417 <td class="pattern">E[foo^="bar"]</td>
418 <td class="meaning">an E element whose "foo" attribute value begins exactly
419 with the string "bar"</td>
420 <td class="described"><a
421 href="#attribute-selectors">Attribute
422 selectors</a></td>
423 <td class="origin">3</td></tr>
424 <tr>
425 <td class="pattern">E[foo$="bar"]</td>
426 <td class="meaning">an E element whose "foo" attribute value ends exactly
427 with the string "bar"</td>
428 <td class="described"><a
429 href="#attribute-selectors">Attribute
430 selectors</a></td>
431 <td class="origin">3</td></tr>
432 <tr>
433 <td class="pattern">E[foo*="bar"]</td>
434 <td class="meaning">an E element whose "foo" attribute value contains the
435 substring "bar"</td>
436 <td class="described"><a
437 href="#attribute-selectors">Attribute
438 selectors</a></td>
439 <td class="origin">3</td></tr>
440 <tr>
441 <td class="pattern">E[hreflang|="en"]</td>
442 <td class="meaning">an E element whose "hreflang" attribute has a hyphen-sep arated
443 list of values beginning (from the left) with "en"</td>
444 <td class="described"><a
445 href="#attribute-selectors">Attribute
446 selectors</a></td>
447 <td class="origin">2</td></tr>
448 <tr>
449 <td class="pattern">E:root</td>
450 <td class="meaning">an E element, root of the document</td>
451 <td class="described"><a
452 href="#structural-pseudos">Structural
453 pseudo-classes</a></td>
454 <td class="origin">3</td></tr>
455 <tr>
456 <td class="pattern">E:nth-child(n)</td>
457 <td class="meaning">an E element, the n-th child of its parent</td>
458 <td class="described"><a
459 href="#structural-pseudos">Structural
460 pseudo-classes</a></td>
461 <td class="origin">3</td></tr>
462 <tr>
463 <td class="pattern">E:nth-last-child(n)</td>
464 <td class="meaning">an E element, the n-th child of its parent, counting
465 from the last one</td>
466 <td class="described"><a
467 href="#structural-pseudos">Structural
468 pseudo-classes</a></td>
469 <td class="origin">3</td></tr>
470 <tr>
471 <td class="pattern">E:nth-of-type(n)</td>
472 <td class="meaning">an E element, the n-th sibling of its type</td>
473 <td class="described"><a
474 href="#structural-pseudos">Structural
475 pseudo-classes</a></td>
476 <td class="origin">3</td></tr>
477 <tr>
478 <td class="pattern">E:nth-last-of-type(n)</td>
479 <td class="meaning">an E element, the n-th sibling of its type, counting
480 from the last one</td>
481 <td class="described"><a
482 href="#structural-pseudos">Structural
483 pseudo-classes</a></td>
484 <td class="origin">3</td></tr>
485 <tr>
486 <td class="pattern">E:first-child</td>
487 <td class="meaning">an E element, first child of its parent</td>
488 <td class="described"><a
489 href="#structural-pseudos">Structural
490 pseudo-classes</a></td>
491 <td class="origin">2</td></tr>
492 <tr>
493 <td class="pattern">E:last-child</td>
494 <td class="meaning">an E element, last child of its parent</td>
495 <td class="described"><a
496 href="#structural-pseudos">Structural
497 pseudo-classes</a></td>
498 <td class="origin">3</td></tr>
499 <tr>
500 <td class="pattern">E:first-of-type</td>
501 <td class="meaning">an E element, first sibling of its type</td>
502 <td class="described"><a
503 href="#structural-pseudos">Structural
504 pseudo-classes</a></td>
505 <td class="origin">3</td></tr>
506 <tr>
507 <td class="pattern">E:last-of-type</td>
508 <td class="meaning">an E element, last sibling of its type</td>
509 <td class="described"><a
510 href="#structural-pseudos">Structural
511 pseudo-classes</a></td>
512 <td class="origin">3</td></tr>
513 <tr>
514 <td class="pattern">E:only-child</td>
515 <td class="meaning">an E element, only child of its parent</td>
516 <td class="described"><a
517 href="#structural-pseudos">Structural
518 pseudo-classes</a></td>
519 <td class="origin">3</td></tr>
520 <tr>
521 <td class="pattern">E:only-of-type</td>
522 <td class="meaning">an E element, only sibling of its type</td>
523 <td class="described"><a
524 href="#structural-pseudos">Structural
525 pseudo-classes</a></td>
526 <td class="origin">3</td></tr>
527 <tr>
528 <td class="pattern">E:empty</td>
529 <td class="meaning">an E element that has no children (including text
530 nodes)</td>
531 <td class="described"><a
532 href="#structural-pseudos">Structural
533 pseudo-classes</a></td>
534 <td class="origin">3</td></tr>
535 <tr>
536 <td class="pattern">E:link<br>E:visited</td>
537 <td class="meaning">an E element being the source anchor of a hyperlink of
538 which the target is not yet visited (:link) or already visited
539 (:visited)</td>
540 <td class="described"><a
541 href="#link">The link
542 pseudo-classes</a></td>
543 <td class="origin">1</td></tr>
544 <tr>
545 <td class="pattern">E:active<br>E:hover<br>E:focus</td>
546 <td class="meaning">an E element during certain user actions</td>
547 <td class="described"><a
548 href="#useraction-pseudos">The user
549 action pseudo-classes</a></td>
550 <td class="origin">1 and 2</td></tr>
551 <tr>
552 <td class="pattern">E:target</td>
553 <td class="meaning">an E element being the target of the referring URI</td>
554 <td class="described"><a
555 href="#target-pseudo">The target
556 pseudo-class</a></td>
557 <td class="origin">3</td></tr>
558 <tr>
559 <td class="pattern">E:lang(fr)</td>
560 <td class="meaning">an element of type E in language "fr" (the document
561 language specifies how language is determined)</td>
562 <td class="described"><a
563 href="#lang-pseudo">The :lang()
564 pseudo-class</a></td>
565 <td class="origin">2</td></tr>
566 <tr>
567 <td class="pattern">E:enabled<br>E:disabled</td>
568 <td class="meaning">a user interface element E which is enabled or
569 disabled</td>
570 <td class="described"><a
571 href="#UIstates">The UI element states
572 pseudo-classes</a></td>
573 <td class="origin">3</td></tr>
574 <tr>
575 <td class="pattern">E:checked<!--<br>E:indeterminate--></td>
576 <td class="meaning">a user interface element E which is checked<!-- or in an
577 indeterminate state--> (for instance a radio-button or checkbox)</td>
578 <td class="described"><a
579 href="#UIstates">The UI element states
580 pseudo-classes</a></td>
581 <td class="origin">3</td></tr>
582 <tr>
583 <td class="pattern">E::first-line</td>
584 <td class="meaning">the first formatted line of an E element</td>
585 <td class="described"><a
586 href="#first-line">The ::first-line
587 pseudo-element</a></td>
588 <td class="origin">1</td></tr>
589 <tr>
590 <td class="pattern">E::first-letter</td>
591 <td class="meaning">the first formatted letter of an E element</td>
592 <td class="described"><a
593 href="#first-letter">The ::first-letter
594 pseudo-element</a></td>
595 <td class="origin">1</td></tr>
596 <tr>
597 <td class="pattern">E::selection</td>
598 <td class="meaning">the portion of an E element that is currently
599 selected/highlighted by the user</td>
600 <td class="described"><a
601 href="#UIfragments">The UI element
602 fragments pseudo-elements</a></td>
603 <td class="origin">3</td></tr>
604 <tr>
605 <td class="pattern">E::before</td>
606 <td class="meaning">generated content before an E element</td>
607 <td class="described"><a
608 href="#gen-content">The ::before
609 pseudo-element</a></td>
610 <td class="origin">2</td></tr>
611 <tr>
612 <td class="pattern">E::after</td>
613 <td class="meaning">generated content after an E element</td>
614 <td class="described"><a
615 href="#gen-content">The ::after
616 pseudo-element</a></td>
617 <td class="origin">2</td></tr>
618 <tr>
619 <td class="pattern">E.warning</td>
620 <td class="meaning">an E element whose class is
621 "warning" (the document language specifies how class is determined).</td>
622 <td class="described"><a
623 href="#class-html">Class
624 selectors</a></td>
625 <td class="origin">1</td></tr>
626 <tr>
627 <td class="pattern">E#myid</td>
628 <td class="meaning">an E element with ID equal to "myid".</td>
629 <td class="described"><a
630 href="#id-selectors">ID
631 selectors</a></td>
632 <td class="origin">1</td></tr>
633 <tr>
634 <td class="pattern">E:not(s)</td>
635 <td class="meaning">an E element that does not match simple selector s</td>
636 <td class="described"><a
637 href="#negation">Negation
638 pseudo-class</a></td>
639 <td class="origin">3</td></tr>
640 <tr>
641 <td class="pattern">E F</td>
642 <td class="meaning">an F element descendant of an E element</td>
643 <td class="described"><a
644 href="#descendant-combinators">Descendant
645 combinator</a></td>
646 <td class="origin">1</td></tr>
647 <tr>
648 <td class="pattern">E &gt; F</td>
649 <td class="meaning">an F element child of an E element</td>
650 <td class="described"><a
651 href="#child-combinators">Child
652 combinator</a></td>
653 <td class="origin">2</td></tr>
654 <tr>
655 <td class="pattern">E + F</td>
656 <td class="meaning">an F element immediately preceded by an E element</td>
657 <td class="described"><a
658 href="#adjacent-sibling-combinators">Adjacent sibling combinator</a></td>
659 <td class="origin">2</td></tr>
660 <tr>
661 <td class="pattern">E ~ F</td>
662 <td class="meaning">an F element preceded by an E element</td>
663 <td class="described"><a
664 href="#general-sibling-combinators">General sibling combinator</a></td>
665 <td class="origin">3</td></tr></tbody></table>
666
667 <p>The meaning of each selector is derived from the table above by
668 prepending "matches" to the contents of each cell in the "Meaning"
669 column.</p>
670
671 <h2><a name=casesens>3. Case sensitivity</a></h2>
672
673 <p>The case sensitivity of document language element names, attribute
674 names, and attribute values in selectors depends on the document
675 language. For example, in HTML, element names are case-insensitive,
676 but in XML, they are case-sensitive.</p>
677
678 <h2><a name=selector-syntax>4. Selector syntax</a></h2>
679
680 <p>A <dfn><a name=selector>selector</a></dfn> is a chain of one
681 or more <a href="#sequence">sequences of simple selectors</a>
682 separated by <a href="#combinators">combinators</a>.</p>
683
684 <p>A <dfn><a name=sequence>sequence of simple selectors</a></dfn>
685 is a chain of <a href="#simple-selectors-dfn">simple selectors</a>
686 that are not separated by a <a href="#combinators">combinator</a>. It
687 always begins with a <a href="#type-selectors">type selector</a> or a
688 <a href="#universal-selector">universal selector</a>. No other type
689 selector or universal selector is allowed in the sequence.</p>
690
691 <p>A <dfn><a name=simple-selectors-dfn></a><a
692 href="#simple-selectors">simple selector</a></dfn> is either a <a
693 href="#type-selectors">type selector</a>, <a
694 href="#universal-selector">universal selector</a>, <a
695 href="#attribute-selectors">attribute selector</a>, <a
696 href="#class-html">class selector</a>, <a
697 href="#id-selectors">ID selector</a>, <a
698 href="#content-selectors">content selector</a>, or <a
699 href="#pseudo-classes">pseudo-class</a>. One <a
700 href="#pseudo-elements">pseudo-element</a> may be appended to the last
701 sequence of simple selectors.</p>
702
703 <p><dfn>Combinators</dfn> are: white space, &quot;greater-than
704 sign&quot; (U+003E, <code>&gt;</code>), &quot;plus sign&quot; (U+002B,
705 <code>+</code>) and &quot;tilde&quot; (U+007E, <code>~</code>). White
706 space may appear between a combinator and the simple selectors around
707 it. <a name=whitespace></a>Only the characters "space" (U+0020), "tab"
708 (U+0009), "line feed" (U+000A), "carriage return" (U+000D), and "form
709 feed" (U+000C) can occur in white space. Other space-like characters,
710 such as "em-space" (U+2003) and "ideographic space" (U+3000), are
711 never part of white space.</p>
712
713 <p>The elements of a document tree that are represented by a selector
714 are the <dfn><a name=subject></a>subjects of the selector</dfn>. A
715 selector consisting of a single sequence of simple selectors
716 represents any element satisfying its requirements. Prepending another
717 sequence of simple selectors and a combinator to a sequence imposes
718 additional matching constraints, so the subjects of a selector are
719 always a subset of the elements represented by the last sequence of
720 simple selectors.</p>
721
722 <p>An empty selector, containing no sequence of simple selectors and
723 no pseudo-element, is an <a href="#Conformance">invalid
724 selector</a>.</p>
725
726 <h2><a name=grouping>5. Groups of selectors</a></h2>
727
728 <p>When several selectors share the same declarations, they may be
729 grouped into a comma-separated list. (A comma is U+002C.)</p>
730
731 <div class="example">
732 <p>CSS examples:</p>
733 <p>In this example, we condense three rules with identical
734 declarations into one. Thus,</p>
735 <pre>h1 { font-family: sans-serif }
736 h2 { font-family: sans-serif }
737 h3 { font-family: sans-serif }</pre>
738 <p>is equivalent to:</p>
739 <pre>h1, h2, h3 { font-family: sans-serif }</pre>
740 </div>
741
742 <p><strong>Warning</strong>: the equivalence is true in this example
743 because all the selectors are valid selectors. If just one of these
744 selectors were invalid, the entire group of selectors would be
745 invalid. This would invalidate the rule for all three heading
746 elements, whereas in the former case only one of the three individual
747 heading rules would be invalidated.</p>
748
749
750 <h2><a name=simple-selectors>6. Simple selectors</a></h2>
751
752 <h3><a name=type-selectors>6.1. Type selector</a></h3>
753
754 <p>A <dfn>type selector</dfn> is the name of a document language
755 element type. A type selector represents an instance of the element
756 type in the document tree.</p>
757
758 <div class="example">
759 <p>Example:</p>
760 <p>The following selector represents an <code>h1</code> element in the document tree:</p>
761 <pre>h1</pre>
762 </div>
763
764
765 <h4><a name=typenmsp>6.1.1. Type selectors and namespaces</a></h4>
766
767 <p>Type selectors allow an optional namespace (<a
768 href="#refsXMLNAMES">[XMLNAMES]</a>) component. A namespace prefix
769 that has been previously declared may be prepended to the element name
770 separated by the namespace separator &quot;vertical bar&quot;
771 (U+007C, <code>|</code>).</p>
772
773 <p>The namespace component may be left empty to indicate that the
774 selector is only to represent elements with no declared namespace.</p>
775
776 <p>An asterisk may be used for the namespace prefix, indicating that
777 the selector represents elements in any namespace (including elements
778 with no namespace).</p>
779
780 <p>Element type selectors that have no namespace component (no
781 namespace separator), represent elements without regard to the
782 element's namespace (equivalent to "<code>*|</code>") unless a default
783 namespace has been declared. If a default namespace has been declared,
784 the selector will represent only elements in the default
785 namespace.</p>
786
787 <p>A type selector containing a namespace prefix that has not been
788 previously declared is an <a href="#Conformance">invalid</a> selector.
789 The mechanism for declaring a namespace prefix is left up to the
790 language implementing Selectors. In CSS, such a mechanism is defined
791 in the General Syntax module.</p>
792
793 <p>In a namespace-aware client, element type selectors will only match
794 against the <a
795 href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local part</a>
796 of the element's <a
797 href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">qualified
798 name</a>. See <a href="#downlevel">below</a> for notes about matching
799 behaviors in down-level clients.</p>
800
801 <p>In summary:</p>
802
803 <dl>
804 <dt><code>ns|E</code></dt>
805 <dd>elements with name E in namespace ns</dd>
806 <dt><code>*|E</code></dt>
807 <dd>elements with name E in any namespace, including those without any
808 declared namespace</dd>
809 <dt><code>|E</code></dt>
810 <dd>elements with name E without any declared namespace</dd>
811 <dt><code>E</code></dt>
812 <dd>if no default namespace has been specified, this is equivalent to *|E.
813 Otherwise it is equivalent to ns|E where ns is the default namespace.</dd>
814 </dl>
815
816 <div class="example">
817 <p>CSS examples:</p>
818
819 <pre>@namespace foo url(http://www.example.com);
820 foo|h1 { color: blue }
821 foo|* { color: yellow }
822 |h1 { color: red }
823 *|h1 { color: green }
824 h1 { color: green }</pre>
825
826 <p>The first rule will match only <code>h1</code> elements in the
827 "http://www.example.com" namespace.</p>
828
829 <p>The second rule will match all elements in the
830 "http://www.example.com" namespace.</p>
831
832 <p>The third rule will match only <code>h1</code> elements without
833 any declared namespace.</p>
834
835 <p>The fourth rule will match <code>h1</code> elements in any
836 namespace (including those without any declared namespace).</p>
837
838 <p>The last rule is equivalent to the fourth rule because no default
839 namespace has been defined.</p>
840
841 </div>
842
843 <h3><a name=universal-selector>6.2. Universal selector</a> </h3>
844
845 <p>The <dfn>universal selector</dfn>, written &quot;asterisk&quot;
846 (<code>*</code>), represents the qualified name of any element
847 type. It represents any single element in the document tree in any
848 namespace (including those without any declared namespace) if no
849 default namespace has been specified. If a default namespace has been
850 specified, see <a href="#univnmsp">Universal selector and
851 Namespaces</a> below.</p>
852
853 <p>If the universal selector is not the only component of a sequence
854 of simple selectors, the <code>*</code> may be omitted.</p>
855
856 <div class="example">
857 <p>Examples:</p>
858 <ul>
859 <li><code>*[hreflang|=en]</code> and <code>[hreflang|=en]</code> are equivalen t,</li>
860 <li><code>*.warning</code> and <code>.warning</code> are equivalent,</li>
861 <li><code>*#myid</code> and <code>#myid</code> are equivalent.</li>
862 </ul>
863 </div>
864
865 <p class="note"><strong>Note:</strong> it is recommended that the
866 <code>*</code>, representing the universal selector, not be
867 omitted.</p>
868
869 <h4><a name=univnmsp>6.2.1. Universal selector and namespaces</a></h4>
870
871 <p>The universal selector allows an optional namespace component. It
872 is used as follows:</p>
873
874 <dl>
875 <dt><code>ns|*</code></dt>
876 <dd>all elements in namespace ns</dd>
877 <dt><code>*|*</code></dt>
878 <dd>all elements</dd>
879 <dt><code>|*</code></dt>
880 <dd>all elements without any declared namespace</dd>
881 <dt><code>*</code></dt>
882 <dd>if no default namespace has been specified, this is equivalent to *|*.
883 Otherwise it is equivalent to ns|* where ns is the default namespace.</dd>
884 </dl>
885
886 <p>A universal selector containing a namespace prefix that has not
887 been previously declared is an <a href="#Conformance">invalid</a>
888 selector. The mechanism for declaring a namespace prefix is left up
889 to the language implementing Selectors. In CSS, such a mechanism is
890 defined in the General Syntax module.</p>
891
892
893 <h3><a name=attribute-selectors>6.3. Attribute selectors</a></h3>
894
895 <p>Selectors allow the representation of an element's attributes. When
896 a selector is used as an expression to match against an element,
897 attribute selectors must be considered to match an element if that
898 element has an attribute that matches the attribute represented by the
899 attribute selector.</p>
900
901 <h4><a name=attribute-representation>6.3.1. Attribute presence and values
902 selectors</a></h4>
903
904 <p>CSS2 introduced four attribute selectors:</p>
905
906 <dl>
907 <dt><code>[att]</code>
908 <dd>Represents an element with the <code>att</code> attribute, whatever the va lue of
909 the attribute.</dd>
910 <dt><code>[att=val]</code></dt>
911 <dd>Represents an element with the <code>att</code> attribute whose value is e xactly
912 "val".</dd>
913 <dt><code>[att~=val]</code></dt>
914 <dd>Represents an element with the <code>att</code> attribute whose value is a <a
915 href="#whitespace">whitespace</a>-separated list of words, one of
916 which is exactly "val". If "val" contains whitespace, it will never
917 represent anything (since the words are <em>separated</em> by
918 spaces).</dd>
919 <dt><code>[att|=val]</code>
920 <dd>Represents an element with the <code>att</code> attribute, its value eithe r
921 being exactly "val" or beginning with "val" immediately followed by
922 "-" (U+002D). This is primarily intended to allow language subcode
923 matches (e.g., the <code>hreflang</code> attribute on the
924 <code>link</code> element in HTML) as described in RFC 3066 (<a
925 href="#refsRFC3066">[RFC3066]</a>). For <code>lang</code> (or
926 <code>xml:lang</code>) language subcode matching, please see <a
927 href="#lang-pseudo">the <code>:lang</code> pseudo-class</a>.</dd>
928 </dl>
929
930 <p>Attribute values must be identifiers or strings. The
931 case-sensitivity of attribute names and values in selectors depends on
932 the document language.</p>
933
934 <div class="example">
935
936 <p>Examples:</p>
937
938 <p>The following attribute selector represents an <code>h1</code>
939 element that carries the <code>title</code> attribute, whatever its
940 value:</p>
941
942 <pre>h1[title]</pre>
943
944 <p>In the following example, the selector represents a
945 <code>span</code> element whose <code>class</code> attribute has
946 exactly the value "example":</p>
947
948 <pre>span[class="example"]</pre>
949
950 <p>Multiple attribute selectors can be used to represent several
951 attributes of an element, or several conditions on the same
952 attribute. Here, the selector represents a <code>span</code> element
953 whose <code>hello</code> attribute has exactly the value "Cleveland"
954 and whose <code>goodbye</code> attribute has exactly the value
955 "Columbus":</p>
956
957 <pre>span[hello="Cleveland"][goodbye="Columbus"]</pre>
958
959 <p>The following selectors illustrate the differences between "="
960 and "~=". The first selector will represent, for example, the value
961 "copyright copyleft copyeditor" on a <code>rel</code> attribute. The
962 second selector will only represent an <code>a</code> element with
963 an <code>href</code> attribute having the exact value
964 "http://www.w3.org/".</p>
965
966 <pre>a[rel~="copyright"]
967 a[href="http://www.w3.org/"]</pre>
968
969 <p>The following selector represents a <code>link</code> element
970 whose <code>hreflang</code> attribute is exactly "fr".</p>
971
972 <pre>link[hreflang=fr]</pre>
973
974 <p>The following selector represents a <code>link</code> element for
975 which the values of the <code>hreflang</code> attribute begins with
976 "en", including "en", "en-US", and "en-cockney":</p>
977
978 <pre>link[hreflang|="en"]</pre>
979
980 <p>Similarly, the following selectors represents a
981 <code>DIALOGUE</code> element whenever it has one of two different
982 values for an attribute <code>character</code>:</p>
983
984 <pre>DIALOGUE[character=romeo]
985 DIALOGUE[character=juliet]</pre>
986
987 </div>
988
989 <h4><a name=attribute-substrings></a>6.3.2. Substring matching attribute
990 selectors</h4>
991
992 <p>Three additional attribute selectors are provided for matching
993 substrings in the value of an attribute:</p>
994
995 <dl>
996 <dt><code>[att^=val]</code></dt>
997 <dd>Represents an element with the <code>att</code> attribute whose value begi ns
998 with the prefix "val".</dd>
999 <dt><code>[att$=val]</code>
1000 <dd>Represents an element with the <code>att</code> attribute whose value ends with
1001 the suffix "val".</dd>
1002 <dt><code>[att*=val]</code>
1003 <dd>Represents an element with the <code>att</code> attribute whose value cont ains
1004 at least one instance of the substring "val".</dd>
1005 </dl>
1006
1007 <p>Attribute values must be identifiers or strings. The
1008 case-sensitivity of attribute names in selectors depends on the
1009 document language.</p>
1010
1011 <div class="example">
1012 <p>Examples:</p>
1013 <p>The following selector represents an HTML <code>object</code>, referencing a n
1014 image:</p>
1015 <pre>object[type^="image/"]</pre>
1016 <p>The following selector represents an HTML anchor <code>a</code> with an
1017 <code>href</code> attribute whose value ends with ".html".</p>
1018 <pre>a[href$=".html"]</pre>
1019 <p>The following selector represents an HTML paragraph with a <code>title</code >
1020 attribute whose value contains the substring "hello"</p>
1021 <pre>p[title*="hello"]</pre>
1022 </div>
1023
1024 <h4><a name=attrnmsp>6.3.3. Attribute selectors and namespaces</a></h4>
1025
1026 <p>Attribute selectors allow an optional namespace component to the
1027 attribute name. A namespace prefix that has been previously declared
1028 may be prepended to the attribute name separated by the namespace
1029 separator &quot;vertical bar&quot; (<code>|</code>). In keeping with
1030 the Namespaces in the XML recommendation, default namespaces do not
1031 apply to attributes, therefore attribute selectors without a namespace
1032 component apply only to attributes that have no declared namespace
1033 (equivalent to "<code>|attr</code>"). An asterisk may be used for the
1034 namespace prefix indicating that the selector is to match all
1035 attribute names without regard to the attribute's namespace.
1036
1037 <p>An attribute selector with an attribute name containing a namespace
1038 prefix that has not been previously declared is an <a
1039 href="#Conformance">invalid</a> selector. The mechanism for declaring
1040 a namespace prefix is left up to the language implementing Selectors.
1041 In CSS, such a mechanism is defined in the General Syntax module.
1042
1043 <div class="example">
1044 <p>CSS examples:</p>
1045 <pre>@namespace foo "http://www.example.com";
1046 [foo|att=val] { color: blue }
1047 [*|att] { color: yellow }
1048 [|att] { color: green }
1049 [att] { color: green }</pre>
1050
1051 <p>The first rule will match only elements with the attribute
1052 <code>att</code> in the "http://www.example.com" namespace with the
1053 value "val".</p>
1054
1055 <p>The second rule will match only elements with the attribute
1056 <code>att</code> regardless of the namespace of the attribute
1057 (including no declared namespace).</p>
1058
1059 <p>The last two rules are equivalent and will match only elements
1060 with the attribute <code>att</code> where the attribute is not
1061 declared to be in a namespace.</p>
1062
1063 </div>
1064
1065 <h4><a name=def-values>6.3.4. Default attribute values in DTDs</a></h4>
1066
1067 <p>Attribute selectors represent explicitly set attribute values in
1068 the document tree. Default attribute values may be defined in a DTD or
1069 elsewhere, but cannot always be selected by attribute
1070 selectors. Selectors should be designed so that they work even if the
1071 default values are not included in the document tree.</p>
1072
1073 <p>More precisely, a UA is <em>not</em> required to read an "external
1074 subset" of the DTD but <em>is</em> required to look for default
1075 attribute values in the document's "internal subset." (See <a
1076 href="#refsXML10">[XML10]</a> for definitions of these subsets.)</p>
1077
1078 <p>A UA that recognizes an XML namespace <a
1079 href="#refsXMLNAMES">[XMLNAMES]</a> is not required to use its
1080 knowledge of that namespace to treat default attribute values as if
1081 they were present in the document. (For example, an XHTML UA is not
1082 required to use its built-in knowledge of the XHTML DTD.)</p>
1083
1084 <p class="note"><strong>Note:</strong> Typically, implementations
1085 choose to ignore external subsets.</p>
1086
1087 <div class="example">
1088 <p>Example:</p>
1089
1090 <p>Consider an element EXAMPLE with an attribute "notation" that has a
1091 default value of "decimal". The DTD fragment might be</p>
1092
1093 <pre class="dtd-example">&lt;!ATTLIST EXAMPLE notation (decimal,octal) "decimal" ></pre>
1094
1095 <p>If the style sheet contains the rules</p>
1096
1097 <pre>EXAMPLE[notation=decimal] { /*... default property settings ...*/ }
1098 EXAMPLE[notation=octal] { /*... other settings...*/ }</pre>
1099
1100 <p>the first rule will not match elements whose "notation" attribute
1101 is set by default, i.e. not set explicitly. To catch all cases, the
1102 attribute selector for the default value must be dropped:</p>
1103
1104 <pre>EXAMPLE { /*... default property settings ...*/ }
1105 EXAMPLE[notation=octal] { /*... other settings...*/ }</pre>
1106
1107 <p>Here, because the selector <code>EXAMPLE[notation=octal]</code> is
1108 more specific than the tag
1109 selector alone, the style declarations in the second rule will override
1110 those in the first for elements that have a "notation" attribute value
1111 of "octal". Care has to be taken that all property declarations that
1112 are to apply only to the default case are overridden in the non-default
1113 cases' style rules.</p>
1114
1115 </div>
1116
1117 <h3><a name=class-html>6.4. Class selectors</a></h3>
1118
1119 <p>Working with HTML, authors may use the period (U+002E,
1120 <code>.</code>) notation as an alternative to the <code>~=</code>
1121 notation when representing the <code>class</code> attribute. Thus, for
1122 HTML, <code>div.value</code> and <code>div[class~=value]</code> have
1123 the same meaning. The attribute value must immediately follow the
1124 &quot;period&quot; (<code>.</code>).</p>
1125
1126 <p>UAs may apply selectors using the period (.) notation in XML
1127 documents if the UA has namespace-specific knowledge that allows it to
1128 determine which attribute is the &quot;class&quot; attribute for the
1129 respective namespace. One such example of namespace-specific knowledge
1130 is the prose in the specification for a particular namespace (e.g. SVG
1131 1.0 <a href="#refsSVG">[SVG]</a> describes the <a
1132 href="http://www.w3.org/TR/2001/PR-SVG-20010719/styling.html#ClassAttribute">SVG
1133 &quot;class&quot; attribute</a> and how a UA should interpret it, and
1134 similarly MathML 1.01 <a href="#refsMATH">[MATH]</a> describes the <a
1135 href="http://www.w3.org/1999/07/REC-MathML-19990707/chapter2.html#sec2.3.4">Math ML
1136 &quot;class&quot; attribute</a>.)</p>
1137
1138 <div class="example">
1139 <p>CSS examples:</p>
1140
1141 <p>We can assign style information to all elements with
1142 <code>class~="pastoral"</code> as follows:</p>
1143
1144 <pre>*.pastoral { color: green } /* all elements with class~=pastoral */</pre >
1145
1146 <p>or just</p>
1147
1148 <pre>.pastoral { color: green } /* all elements with class~=pastoral */</pre>
1149
1150 <p>The following assigns style only to H1 elements with
1151 <code>class~="pastoral"</code>:</p>
1152
1153 <pre>H1.pastoral { color: green } /* H1 elements with class~=pastoral */</pre >
1154
1155 <p>Given these rules, the first H1 instance below would not have
1156 green text, while the second would:</p>
1157
1158 <pre>&lt;H1&gt;Not green&lt;/H1&gt;
1159 &lt;H1 class="pastoral"&gt;Very green&lt;/H1&gt;</pre>
1160
1161 </div>
1162
1163 <p>To represent a subset of "class" values, each value must be preceded
1164 by a ".", in any order.</P>
1165
1166 <div class="example">
1167
1168 <p>CSS example:</p>
1169
1170 <p>The following rule matches any P element whose "class" attribute
1171 has been assigned a list of <a
1172 href="#whitespace">whitespace</a>-separated values that includes
1173 "pastoral" and "marine":</p>
1174
1175 <pre>p.pastoral.marine { color: green }</pre>
1176
1177 <p>This rule matches when <code>class="pastoral blue aqua
1178 marine"</code> but does not match for <code>class="pastoral
1179 blue"</code>.</p>
1180
1181 </div>
1182
1183 <p class="note"><strong>Note:</strong> Because CSS gives considerable
1184 power to the "class" attribute, authors could conceivably design their
1185 own "document language" based on elements with almost no associated
1186 presentation (such as DIV and SPAN in HTML) and assigning style
1187 information through the "class" attribute. Authors should avoid this
1188 practice since the structural elements of a document language often
1189 have recognized and accepted meanings and author-defined classes may
1190 not.</p>
1191
1192 <p class="note"><strong>Note:</strong> If an element has multiple
1193 class attributes, their values must be concatenated with spaces
1194 between the values before searching for the class. As of this time the
1195 working group is not aware of any manner in which this situation can
1196 be reached, however, so this behavior is explicitly non-normative in
1197 this specification.</p>
1198
1199 <h3><a name=id-selectors>6.5. ID selectors</a></h3>
1200
1201 <p>Document languages may contain attributes that are declared to be
1202 of type ID. What makes attributes of type ID special is that no two
1203 such attributes can have the same value in a document, regardless of
1204 the type of the elements that carry them; whatever the document
1205 language, an ID typed attribute can be used to uniquely identify its
1206 element. In HTML all ID attributes are named "id"; XML applications
1207 may name ID attributes differently, but the same restriction
1208 applies.</p>
1209
1210 <p>An ID-typed attribute of a document language allows authors to
1211 assign an identifier to one element instance in the document tree. W3C
1212 ID selectors represent an element instance based on its identifier. An
1213 ID selector contains a &quot;number sign&quot; (U+0023,
1214 <code>#</code>) immediately followed by the ID value, which must be an
1215 identifier.</p>
1216
1217 <p>Selectors does not specify how a UA knows the ID-typed attribute of
1218 an element. The UA may, e.g., read a document's DTD, have the
1219 information hard-coded or ask the user.
1220
1221 <div class="example">
1222 <p>Examples:</p>
1223 <p>The following ID selector represents an <code>h1</code> element
1224 whose ID-typed attribute has the value "chapter1":</p>
1225 <pre>h1#chapter1</pre>
1226 <p>The following ID selector represents any element whose ID-typed
1227 attribute has the value "chapter1":</p>
1228 <pre>#chapter1</pre>
1229 <p>The following selector represents any element whose ID-typed
1230 attribute has the value "z98y".</p>
1231 <pre>*#z98y</pre>
1232 </div>
1233
1234 <p class="note"><strong>Note.</strong> In XML 1.0 <a
1235 href="#refsXML10">[XML10]</a>, the information about which attribute
1236 contains an element's IDs is contained in a DTD or a schema. When
1237 parsing XML, UAs do not always read the DTD, and thus may not know
1238 what the ID of an element is (though a UA may have namespace-specific
1239 knowledge that allows it to determine which attribute is the ID
1240 attribute for that namespace). If a style sheet designer knows or
1241 suspects that a UA may not know what the ID of an element is, he
1242 should use normal attribute selectors instead:
1243 <code>[name=p371]</code> instead of <code>#p371</code>. Elements in
1244 XML 1.0 documents without a DTD do not have IDs at all.</p>
1245
1246 <p>If an element has multiple ID attributes, all of them must be
1247 treated as IDs for that element for the purposes of the ID
1248 selector. Such a situation could be reached using mixtures of xml:id,
1249 DOM3 Core, XML DTDs, and namespace-specific knowledge.</p>
1250
1251 <h3><a name=pseudo-classes>6.6. Pseudo-classes</a></h3>
1252
1253 <p>The pseudo-class concept is introduced to permit selection based on
1254 information that lies outside of the document tree or that cannot be
1255 expressed using the other simple selectors.</p>
1256
1257 <p>A pseudo-class always consists of a &quot;colon&quot;
1258 (<code>:</code>) followed by the name of the pseudo-class and
1259 optionally by a value between parentheses.</p>
1260
1261 <p>Pseudo-classes are allowed in all sequences of simple selectors
1262 contained in a selector. Pseudo-classes are allowed anywhere in
1263 sequences of simple selectors, after the leading type selector or
1264 universal selector (possibly omitted). Pseudo-class names are
1265 case-insensitive. Some pseudo-classes are mutually exclusive, while
1266 others can be applied simultaneously to the same
1267 element. Pseudo-classes may be dynamic, in the sense that an element
1268 may acquire or lose a pseudo-class while a user interacts with the
1269 document.</p>
1270
1271
1272 <h4><a name=dynamic-pseudos>6.6.1. Dynamic pseudo-classes</a></h4>
1273
1274 <p>Dynamic pseudo-classes classify elements on characteristics other
1275 than their name, attributes, or content, in principle characteristics
1276 that cannot be deduced from the document tree.</p>
1277
1278 <p>Dynamic pseudo-classes do not appear in the document source or
1279 document tree.</p>
1280
1281
1282 <h5>The <a name=link>link pseudo-classes: :link and :visited</a></h5>
1283
1284 <p>User agents commonly display unvisited links differently from
1285 previously visited ones. Selectors
1286 provides the pseudo-classes <code>:link</code> and
1287 <code>:visited</code> to distinguish them:</p>
1288
1289 <ul>
1290 <li>The <code>:link</code> pseudo-class applies to links that have
1291 not yet been visited.</li>
1292 <li>The <code>:visited</code> pseudo-class applies once the link has
1293 been visited by the user. </li>
1294 </ul>
1295
1296 <p>After some amount of time, user agents may choose to return a
1297 visited link to the (unvisited) ':link' state.</p>
1298
1299 <p>The two states are mutually exclusive.</p>
1300
1301 <div class="example">
1302
1303 <p>Example:</p>
1304
1305 <p>The following selector represents links carrying class
1306 <code>external</code> and already visited:</p>
1307
1308 <pre>a.external:visited</pre>
1309
1310 </div>
1311
1312 <p class="note"><strong>Note:</strong> It is possible for style sheet
1313 authors to abuse the :link and :visited pseudo-classes to determine
1314 which sites a user has visited without the user's consent.
1315
1316 <p>UAs may therefore treat all links as unvisited links, or implement
1317 other measures to preserve the user's privacy while rendering visited
1318 and unvisited links differently.</p>
1319
1320 <h5>The <a name=useraction-pseudos>user action pseudo-classes
1321 :hover, :active, and :focus</a></h5>
1322
1323 <p>Interactive user agents sometimes change the rendering in response
1324 to user actions. Selectors provides
1325 three pseudo-classes for the selection of an element the user is
1326 acting on.</p>
1327
1328 <ul>
1329
1330 <li>The <code>:hover</code> pseudo-class applies while the user
1331 designates an element with a pointing device, but does not activate
1332 it. For example, a visual user agent could apply this pseudo-class
1333 when the cursor (mouse pointer) hovers over a box generated by the
1334 element. User agents not that do not support <a
1335 href="http://www.w3.org/TR/REC-CSS2/media.html#interactive-media-group">intera ctive
1336 media</a> do not have to support this pseudo-class. Some conforming
1337 user agents that support <a
1338 href="http://www.w3.org/TR/REC-CSS2/media.html#interactive-media-group">intera ctive
1339 media</a> may not be able to support this pseudo-class (e.g., a pen
1340 device that does not detect hovering).</li>
1341
1342 <li>The <code>:active</code> pseudo-class applies while an element
1343 is being activated by the user. For example, between the times the
1344 user presses the mouse button and releases it.</li>
1345
1346 <li>The <code>:focus</code> pseudo-class applies while an element
1347 has the focus (accepts keyboard or mouse events, or other forms of
1348 input). </li>
1349
1350 </ul>
1351
1352 <p>There may be document language or implementation specific limits on
1353 which elements can become <code>:active</code> or acquire
1354 <code>:focus</code>.</p>
1355
1356 <p>These pseudo-classes are not mutually exclusive. An element may
1357 match several pseudo-classes at the same time.</p>
1358
1359 <p>Selectors doesn't define if the parent of an element that is
1360 ':active' or ':hover' is also in that state.</p>
1361
1362 <div class="example">
1363 <p>Examples:</p>
1364 <pre>a:link /* unvisited links */
1365 a:visited /* visited links */
1366 a:hover /* user hovers */
1367 a:active /* active links */</pre>
1368 <p>An example of combining dynamic pseudo-classes:</p>
1369 <pre>a:focus
1370 a:focus:hover</pre>
1371 <p>The last selector matches <code>a</code> elements that are in
1372 the pseudo-class :focus and in the pseudo-class :hover.</p>
1373 </div>
1374
1375 <p class="note"><strong>Note:</strong> An element can be both ':visited'
1376 and ':active' (or ':link' and ':active').</p>
1377
1378 <h4><a name=target-pseudo>6.6.2. The target pseudo-class :target</a></h4>
1379
1380 <p>Some URIs refer to a location within a resource. This kind of URI
1381 ends with a &quot;number sign&quot; (#) followed by an anchor
1382 identifier (called the fragment identifier).</p>
1383
1384 <p>URIs with fragment identifiers link to a certain element within the
1385 document, known as the target element. For instance, here is a URI
1386 pointing to an anchor named <code>section_2</code> in an HTML
1387 document:</p>
1388
1389 <pre>http://example.com/html/top.html#section_2</pre>
1390
1391 <p>A target element can be represented by the <code>:target</code>
1392 pseudo-class. If the document's URI has no fragment identifier, then
1393 the document has no target element.</p>
1394
1395 <div class="example">
1396 <p>Example:</p>
1397 <pre>p.note:target</pre>
1398 <p>This selector represents a <code>p</code> element of class
1399 <code>note</code> that is the target element of the referring
1400 URI.</p>
1401 </div>
1402
1403 <div class="example">
1404 <p>CSS example:</p>
1405 <p>Here, the <code>:target</code> pseudo-class is used to make the
1406 target element red and place an image before it, if there is one:</p>
1407 <pre>*:target { color : red }
1408 *:target::before { content : url(target.png) }</pre>
1409 </div>
1410
1411 <h4><a name=lang-pseudo>6.6.3. The language pseudo-class :lang</a></h4>
1412
1413 <p>If the document language specifies how the human language of an
1414 element is determined, it is possible to write selectors that
1415 represent an element based on its language. For example, in HTML <a
1416 href="#refsHTML4">[HTML4]</a>, the language is determined by a
1417 combination of the <code>lang</code> attribute, the <code>meta</code>
1418 element, and possibly by information from the protocol (such as HTTP
1419 headers). XML uses an attribute called <code>xml:lang</code>, and
1420 there may be other document language-specific methods for determining
1421 the language.</p>
1422
1423 <p>The pseudo-class <code>:lang(C)</code> represents an element that
1424 is in language C. Whether an element is represented by a
1425 <code>:lang()</code> selector is based solely on the identifier C
1426 being either equal to, or a hyphen-separated substring of, the
1427 element's language value, in the same way as if performed by the <a
1428 href="#attribute-representation">'|='</a> operator in attribute
1429 selectors. The identifier C does not have to be a valid language
1430 name.</p>
1431
1432 <p>C must not be empty. (If it is, the selector is invalid.)</p>
1433
1434 <p class="note"><strong>Note:</strong> It is recommended that
1435 documents and protocols indicate language using codes from RFC 3066 <a
1436 href="#refsRFC3066">[RFC3066]</a> or its successor, and by means of
1437 "xml:lang" attributes in the case of XML-based documents <a
1438 href="#refsXML10">[XML10]</a>. See <a
1439 href="http://www.w3.org/International/questions/qa-lang-2or3.html">
1440 "FAQ: Two-letter or three-letter language codes."</a></p>
1441
1442 <div class="example">
1443 <p>Examples:</p>
1444 <p>The two following selectors represent an HTML document that is in
1445 Belgian, French, or German. The two next selectors represent
1446 <code>q</code> quotations in an arbitrary element in Belgian, French,
1447 or German.</p>
1448 <pre>html:lang(fr-be)
1449 html:lang(de)
1450 :lang(fr-be) &gt; q
1451 :lang(de) &gt; q</pre>
1452 </div>
1453
1454 <h4><a name=UIstates>6.6.4. The UI element states pseudo-classes</a></h4>
1455
1456 <h5><a name=enableddisabled>The :enabled and :disabled pseudo-classes</a></h5>
1457
1458 <p>The <code>:enabled</code> pseudo-class allows authors to customize
1459 the look of user interface elements that are enabled &mdash; which the
1460 user can select or activate in some fashion (e.g. clicking on a button
1461 with a mouse). There is a need for such a pseudo-class because there
1462 is no way to programmatically specify the default appearance of say,
1463 an enabled <code>input</code> element without also specifying what it
1464 would look like when it was disabled.</p>
1465
1466 <p>Similar to <code>:enabled</code>, <code>:disabled</code> allows the
1467 author to specify precisely how a disabled or inactive user interface
1468 element should look.</p>
1469
1470 <p>Most elements will be neither enabled nor disabled. An element is
1471 enabled if the user can either activate it or transfer the focus to
1472 it. An element is disabled if it could be enabled, but the user cannot
1473 presently activate it or transfer focus to it.</p>
1474
1475
1476 <h5><a name=checked>The :checked pseudo-class</a></h5>
1477
1478 <p>Radio and checkbox elements can be toggled by the user. Some menu
1479 items are "checked" when the user selects them. When such elements are
1480 toggled "on" the <code>:checked</code> pseudo-class applies. The
1481 <code>:checked</code> pseudo-class initially applies to such elements
1482 that have the HTML4 <code>selected</code> and <code>checked</code>
1483 attributes as described in <a
1484 href="http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.2.1">Section
1485 17.2.1 of HTML4</a>, but of course the user can toggle "off" such
1486 elements in which case the <code>:checked</code> pseudo-class would no
1487 longer apply. While the <code>:checked</code> pseudo-class is dynamic
1488 in nature, and is altered by user action, since it can also be based
1489 on the presence of the semantic HTML4 <code>selected</code> and
1490 <code>checked</code> attributes, it applies to all media.
1491
1492
1493 <h5><a name=indeterminate>The :indeterminate pseudo-class</a></h5>
1494
1495 <div class="note">
1496
1497 <p>Radio and checkbox elements can be toggled by the user, but are
1498 sometimes in an indeterminate state, neither checked nor unchecked.
1499 This can be due to an element attribute, or DOM manipulation.</p>
1500
1501 <p>A future version of this specification may introduce an
1502 <code>:indeterminate</code> pseudo-class that applies to such elements.
1503 <!--While the <code>:indeterminate</code> pseudo-class is dynamic in
1504 nature, and is altered by user action, since it can also be based on
1505 the presence of an element attribute, it applies to all media.</p>
1506
1507 <p>Components of a radio-group initialized with no pre-selected choice
1508 are an example of :indeterminate state.--></p>
1509
1510 </div>
1511
1512
1513 <h4><a name=structural-pseudos>6.6.5. Structural pseudo-classes</a></h4>
1514
1515 <p>Selectors introduces the concept of <dfn>structural
1516 pseudo-classes</dfn> to permit selection based on extra information that lies in
1517 the document tree but cannot be represented by other simple selectors or
1518 combinators.
1519
1520 <p>Note that standalone pieces of PCDATA (text nodes in the DOM) are
1521 not counted when calculating the position of an element in the list of
1522 children of its parent. When calculating the position of an element in
1523 the list of children of its parent, the index numbering starts at 1.
1524
1525
1526 <h5><a name=root-pseudo>:root pseudo-class</a></h5>
1527
1528 <p>The <code>:root</code> pseudo-class represents an element that is
1529 the root of the document. In HTML 4, this is always the
1530 <code>HTML</code> element.
1531
1532
1533 <h5><a name=nth-child-pseudo>:nth-child() pseudo-class</a></h5>
1534
1535 <p>The
1536 <code>:nth-child(<var>a</var><code>n</code>+<var>b</var>)</code>
1537 pseudo-class notation represents an element that has
1538 <var>a</var><code>n</code>+<var>b</var>-1 siblings
1539 <strong>before</strong> it in the document tree, for a given positive
1540 integer or zero value of <code>n</code>, and has a parent element. In
1541 other words, this matches the <var>b</var>th child of an element after
1542 all the children have been split into groups of <var>a</var> elements
1543 each. For example, this allows the selectors to address every other
1544 row in a table, and could be used to alternate the color
1545 of paragraph text in a cycle of four. The <var>a</var> and
1546 <var>b</var> values must be zero, negative integers or positive
1547 integers. The index of the first child of an element is 1.
1548
1549 <p>In addition to this, <code>:nth-child()</code> can take
1550 '<code>odd</code>' and '<code>even</code>' as arguments instead.
1551 '<code>odd</code>' has the same signification as <code>2n+1</code>,
1552 and '<code>even</code>' has the same signification as <code>2n</code>.
1553
1554
1555 <div class="example">
1556 <p>Examples:</p>
1557 <pre>tr:nth-child(2n+1) /* represents every odd row of an HTML table */
1558 tr:nth-child(odd) /* same */
1559 tr:nth-child(2n) /* represents every even row of an HTML table */
1560 tr:nth-child(even) /* same */
1561
1562 /* Alternate paragraph colours in CSS */
1563 p:nth-child(4n+1) { color: navy; }
1564 p:nth-child(4n+2) { color: green; }
1565 p:nth-child(4n+3) { color: maroon; }
1566 p:nth-child(4n+4) { color: purple; }</pre>
1567 </div>
1568
1569 <p>When <var>a</var>=0, no repeating is used, so for example
1570 <code>:nth-child(0n+5)</code> matches only the fifth child. When
1571 <var>a</var>=0, the <var>a</var><code>n</code> part need not be
1572 included, so the syntax simplifies to
1573 <code>:nth-child(<var>b</var>)</code> and the last example simplifies
1574 to <code>:nth-child(5)</code>.
1575
1576 <div class="example">
1577 <p>Examples:</p>
1578 <pre>foo:nth-child(0n+1) /* represents an element foo, first child of its pare nt element */
1579 foo:nth-child(1) /* same */</pre>
1580 </div>
1581
1582 <p>When <var>a</var>=1, the number may be omitted from the rule.
1583
1584 <div class="example">
1585 <p>Examples:</p>
1586 <p>The following selectors are therefore equivalent:</p>
1587 <pre>bar:nth-child(1n+0) /* represents all bar elements, specificity (0,1,1) * /
1588 bar:nth-child(n+0) /* same */
1589 bar:nth-child(n) /* same */
1590 bar /* same but lower specificity (0,0,1) */</pre>
1591 </div>
1592
1593 <p>If <var>b</var>=0, then every <var>a</var>th element is picked. In
1594 such a case, the <var>b</var> part may be omitted.
1595
1596 <div class="example">
1597 <p>Examples:</p>
1598 <pre>tr:nth-child(2n+0) /* represents every even row of an HTML table */
1599 tr:nth-child(2n) /* same */</pre>
1600 </div>
1601
1602 <p>If both <var>a</var> and <var>b</var> are equal to zero, the
1603 pseudo-class represents no element in the document tree.</p>
1604
1605 <p>The value <var>a</var> can be negative, but only the positive
1606 values of <var>a</var><code>n</code>+<var>b</var>, for
1607 <code>n</code>&ge;0, may represent an element in the document
1608 tree.</p>
1609
1610 <div class="example">
1611 <p>Example:</p>
1612 <pre>html|tr:nth-child(-n+6) /* represents the 6 first rows of XHTML tables */< /pre>
1613 </div>
1614
1615 <p>When the value <var>b</var> is negative, the "+" character in the
1616 expression must be removed (it is effectively replaced by the "-"
1617 character indicating the negative value of <var>b</var>).</p>
1618
1619 <div class="example">
1620 <p>Examples:</p>
1621 <pre>:nth-child(10n-1) /* represents the 9th, 19th, 29th, etc, element */
1622 :nth-child(10n+9) /* Same */
1623 :nth-child(10n+-1) /* Syntactically invalid, and would be ignored */</pre>
1624 </div>
1625
1626
1627 <h5><a name=nth-last-child-pseudo>:nth-last-child() pseudo-class</a></h5>
1628
1629 <p>The <code>:nth-last-child(<var>a</var>n+<var>b</var>)</code>
1630 pseudo-class notation represents an element that has
1631 <var>a</var><code>n</code>+<var>b</var>-1 siblings
1632 <strong>after</strong> it in the document tree, for a given positive
1633 integer or zero value of <code>n</code>, and has a parent element. See
1634 <code>:nth-child()</code> pseudo-class for the syntax of its argument.
1635 It also accepts the '<code>even</code>' and '<code>odd</code>' values
1636 as arguments.
1637
1638
1639 <div class="example">
1640 <p>Examples:</p>
1641 <pre>tr:nth-last-child(-n+2) /* represents the two last rows of an HTML table */
1642
1643 foo:nth-last-child(odd) /* represents all odd foo elements in their parent el ement,
1644 counting from the last one */</pre>
1645 </div>
1646
1647
1648 <h5><a name=nth-of-type-pseudo>:nth-of-type() pseudo-class</a></h5>
1649
1650 <p>The <code>:nth-of-type(<var>a</var>n+<var>b</var>)</code>
1651 pseudo-class notation represents an element that has
1652 <var>a</var><code>n</code>+<var>b</var>-1 siblings with the same
1653 element name <strong>before</strong> it in the document tree, for a
1654 given zero or positive integer value of <code>n</code>, and has a
1655 parent element. In other words, this matches the <var>b</var>th child
1656 of that type after all the children of that type have been split into
1657 groups of a elements each. See <code>:nth-child()</code> pseudo-class
1658 for the syntax of its argument. It also accepts the
1659 '<code>even</code>' and '<code>odd</code>' values.
1660
1661
1662 <div class="example">
1663 <p>CSS example:</p>
1664 <p>This allows an author to alternate the position of floated images:</p>
1665 <pre>img:nth-of-type(2n+1) { float: right; }
1666 img:nth-of-type(2n) { float: left; }</pre>
1667 </div>
1668
1669
1670 <h5><a name=nth-last-of-type-pseudo>:nth-last-of-type() pseudo-class</a></h5>
1671
1672 <p>The <code>:nth-last-of-type(<var>a</var>n+<var>b</var>)</code>
1673 pseudo-class notation represents an element that has
1674 <var>a</var><code>n</code>+<var>b</var>-1 siblings with the same
1675 element name <strong>after</strong> it in the document tree, for a
1676 given zero or positive integer value of <code>n</code>, and has a
1677 parent element. See <code>:nth-child()</code> pseudo-class for the
1678 syntax of its argument. It also accepts the '<code>even</code>' and '<code>odd</ code>' values.
1679
1680
1681 <div class="example">
1682 <p>Example:</p>
1683 <p>To represent all <code>h2</code> children of an XHTML
1684 <code>body</code> except the first and last, one could use the
1685 following selector:</p>
1686 <pre>body &gt; h2:nth-of-type(n+2):nth-last-of-type(n+2)</pre>
1687 <p>In this case, one could also use <code>:not()</code>, although the
1688 selector ends up being just as long:</p>
1689 <pre>body &gt; h2:not(:first-of-type):not(:last-of-type)</pre>
1690 </div>
1691
1692
1693 <h5><a name=first-child-pseudo>:first-child pseudo-class</a></h5>
1694
1695 <p>Same as <code>:nth-child(1)</code>. The <code>:first-child</code> pseudo-clas s
1696 represents an element that is the first child of some other element.
1697
1698
1699 <div class="example">
1700 <p>Examples:</p>
1701 <p>The following selector represents a <code>p</code> element that is
1702 the first child of a <code>div</code> element:</p>
1703 <pre>div &gt; p:first-child</pre>
1704 <p>This selector can represent the <code>p</code> inside the
1705 <code>div</code> of the following fragment:</p>
1706 <pre>&lt;p&gt; The last P before the note.&lt;/p&gt;
1707 &lt;div class="note"&gt;
1708 &lt;p&gt; The first P inside the note.&lt;/p&gt;
1709 &lt;/div&gt;</pre>but cannot represent the second <code>p</code> in the followin g
1710 fragment:
1711 <pre>&lt;p&gt; The last P before the note.&lt;/p&gt;
1712 &lt;div class="note"&gt;
1713 &lt;h2&gt; Note &lt;/h2&gt;
1714 &lt;p&gt; The first P inside the note.&lt;/p&gt;
1715 &lt;/div&gt;</pre>
1716 <p>The following two selectors are usually equivalent:</p>
1717 <pre>* &gt; a:first-child /* a is first child of any element */
1718 a:first-child /* Same (assuming a is not the root element) */</pre>
1719 </div>
1720
1721 <h5><a name=last-child-pseudo>:last-child pseudo-class</a></h5>
1722
1723 <p>Same as <code>:nth-last-child(1)</code>. The <code>:last-child</code> pseudo- class
1724 represents an element that is the last child of some other element.
1725
1726 <div class="example">
1727 <p>Example:</p>
1728 <p>The following selector represents a list item <code>li</code> that
1729 is the last child of an ordered list <code>ol</code>.
1730 <pre>ol &gt; li:last-child</pre>
1731 </div>
1732
1733 <h5><a name=first-of-type-pseudo>:first-of-type pseudo-class</a></h5>
1734
1735 <p>Same as <code>:nth-of-type(1)</code>. The <code>:first-of-type</code> pseudo- class
1736 represents an element that is the first sibling of its type in the list of
1737 children of its parent element.
1738
1739 <div class="example">
1740 <p>Example:</p>
1741 <p>The following selector represents a definition title
1742 <code>dt</code> inside a definition list <code>dl</code>, this
1743 <code>dt</code> being the first of its type in the list of children of
1744 its parent element.</p>
1745 <pre>dl dt:first-of-type</pre>
1746 <p>It is a valid description for the first two <code>dt</code>
1747 elements in the following example but not for the third one:</p>
1748 <pre>&lt;dl&gt;
1749 &lt;dt&gt;gigogne&lt;/dt&gt;
1750 &lt;dd&gt;
1751 &lt;dl&gt;
1752 &lt;dt&gt;fus&eacute;e&lt;/dt&gt;
1753 &lt;dd&gt;multistage rocket&lt;/dd&gt;
1754 &lt;dt&gt;table&lt;/dt&gt;
1755 &lt;dd&gt;nest of tables&lt;/dd&gt;
1756 &lt;/dl&gt;
1757 &lt;/dd&gt;
1758 &lt;/dl&gt;</pre>
1759 </div>
1760
1761 <h5><a name=last-of-type-pseudo>:last-of-type pseudo-class</a></h5>
1762
1763 <p>Same as <code>:nth-last-of-type(1)</code>. The
1764 <code>:last-of-type</code> pseudo-class represents an element that is
1765 the last sibling of its type in the list of children of its parent
1766 element.</p>
1767
1768 <div class="example">
1769 <p>Example:</p>
1770 <p>The following selector represents the last data cell
1771 <code>td</code> of a table row.</p>
1772 <pre>tr &gt; td:last-of-type</pre>
1773 </div>
1774
1775 <h5><a name=only-child-pseudo>:only-child pseudo-class</a></h5>
1776
1777 <p>Represents an element that has a parent element and whose parent
1778 element has no other element children. Same as
1779 <code>:first-child:last-child</code> or
1780 <code>:nth-child(1):nth-last-child(1)</code>, but with a lower
1781 specificity.</p>
1782
1783 <h5><a name=only-of-type-pseudo>:only-of-type pseudo-class</a></h5>
1784
1785 <p>Represents an element that has a parent element and whose parent
1786 element has no other element children with the same element name. Same
1787 as <code>:first-of-type:last-of-type</code> or
1788 <code>:nth-of-type(1):nth-last-of-type(1)</code>, but with a lower
1789 specificity.</p>
1790
1791
1792 <h5><a name=empty-pseudo></a>:empty pseudo-class</h5>
1793
1794 <p>The <code>:empty</code> pseudo-class represents an element that has
1795 no children at all. In terms of the DOM, only element nodes and text
1796 nodes (including CDATA nodes and entity references) whose data has a
1797 non-zero length must be considered as affecting emptiness; comments,
1798 PIs, and other nodes must not affect whether an element is considered
1799 empty or not.</p>
1800
1801 <div class="example">
1802 <p>Examples:</p>
1803 <p><code>p:empty</code> is a valid representation of the following fragment:</p >
1804 <pre>&lt;p&gt;&lt;/p&gt;</pre>
1805 <p><code>foo:empty</code> is not a valid representation for the
1806 following fragments:</p>
1807 <pre>&lt;foo&gt;bar&lt;/foo&gt;</pre>
1808 <pre>&lt;foo&gt;&lt;bar&gt;bla&lt;/bar&gt;&lt;/foo&gt;</pre>
1809 <pre>&lt;foo&gt;this is not &lt;bar&gt;:empty&lt;/bar&gt;&lt;/foo&gt;</pre>
1810 </div>
1811
1812 <h4><a name=content-selectors>6.6.6. Blank</a></h4> <!-- It's the Return of Appe ndix H!!! Run away! -->
1813
1814 <p>This section intentionally left blank.</p>
1815 <!-- (used to be :contains()) -->
1816
1817 <h4><a name=negation></a>6.6.7. The negation pseudo-class</h4>
1818
1819 <p>The negation pseudo-class, <code>:not(<var>X</var>)</code>, is a
1820 functional notation taking a <a href="#simple-selectors-dfn">simple
1821 selector</a> (excluding the negation pseudo-class itself and
1822 pseudo-elements) as an argument. It represents an element that is not
1823 represented by the argument.
1824
1825 <!-- pseudo-elements are not simple selectors, so the above paragraph
1826 may be a bit confusing -->
1827
1828 <div class="example">
1829 <p>Examples:</p>
1830 <p>The following CSS selector matches all <code>button</code>
1831 elements in an HTML document that are not disabled.</p>
1832 <pre>button:not([DISABLED])</pre>
1833 <p>The following selector represents all but <code>FOO</code>
1834 elements.</p>
1835 <pre>*:not(FOO)</pre>
1836 <p>The following group of selectors represents all HTML elements
1837 except links.</p>
1838 <pre>html|*:not(:link):not(:visited)</pre>
1839 </div>
1840
1841 <p>Default namespace declarations do not affect the argument of the
1842 negation pseudo-class unless the argument is a universal selector or a
1843 type selector.</p>
1844
1845 <div class="example">
1846 <p>Examples:</p>
1847 <p>Assuming that the default namespace is bound to
1848 "http://example.com/", the following selector represents all
1849 elements that are not in that namespace:</p>
1850 <pre>*|*:not(*)</pre>
1851 <p>The following CSS selector matches any element being hovered,
1852 regardless of its namespace. In particular, it is not limited to
1853 only matching elements in the default namespace that are not being
1854 hovered, and elements not in the default namespace don't match the
1855 rule when they <em>are</em> being hovered.</p>
1856 <pre>*|*:not(:hover)</pre>
1857 </div>
1858
1859 <p class="note"><strong>Note</strong>: the :not() pseudo allows
1860 useless selectors to be written. For instance <code>:not(*|*)</code>,
1861 which represents no element at all, or <code>foo:not(bar)</code>,
1862 which is equivalent to <code>foo</code> but with a higher
1863 specificity.</p>
1864
1865 <h3><a name=pseudo-elements>7. Pseudo-elements</a></h3>
1866
1867 <p>Pseudo-elements create abstractions about the document tree beyond
1868 those specified by the document language. For instance, document
1869 languages do not offer mechanisms to access the first letter or first
1870 line of an element's content. Pseudo-elements allow designers to refer
1871 to this otherwise inaccessible information. Pseudo-elements may also
1872 provide designers a way to refer to content that does not exist in the
1873 source document (e.g., the <code>::before</code> and
1874 <code>::after</code> pseudo-elements give access to generated
1875 content).</p>
1876
1877 <p>A pseudo-element is made of two colons (<code>::</code>) followed
1878 by the name of the pseudo-element.</p>
1879
1880 <p>This <code>::</code> notation is introduced by the current document
1881 in order to establish a discrimination between pseudo-classes and
1882 pseudo-elements. For compatibility with existing style sheets, user
1883 agents must also accept the previous one-colon notation for
1884 pseudo-elements introduced in CSS levels 1 and 2 (namely,
1885 <code>:first-line</code>, <code>:first-letter</code>,
1886 <code>:before</code> and <code>:after</code>). This compatibility is
1887 not allowed for the new pseudo-elements introduced in CSS level 3.</p>
1888
1889 <p>Only one pseudo-element may appear per selector, and if present it
1890 must appear after the sequence of simple selectors that represents the
1891 <a href="#subject">subjects</a> of the selector. <span class="note">A
1892 future version of this specification may allow multiple
1893 pesudo-elements per selector.</span></p>
1894
1895 <h4><a name=first-line>7.1. The ::first-line pseudo-element</a></h4>
1896
1897 <p>The <code>::first-line</code> pseudo-element describes the contents
1898 of the first formatted line of an element.
1899
1900 <div class="example">
1901 <p>CSS example:</p>
1902 <pre>p::first-line { text-transform: uppercase }</pre>
1903 <p>The above rule means "change the letters of the first line of every
1904 paragraph to uppercase".</p>
1905 </div>
1906
1907 <p>The selector <code>p::first-line</code> does not match any real
1908 HTML element. It does match a pseudo-element that conforming user
1909 agents will insert at the beginning of every paragraph.</p>
1910
1911 <p>Note that the length of the first line depends on a number of
1912 factors, including the width of the page, the font size, etc. Thus,
1913 an ordinary HTML paragraph such as:</p>
1914
1915 <pre>
1916 &lt;P&gt;This is a somewhat long HTML
1917 paragraph that will be broken into several
1918 lines. The first line will be identified
1919 by a fictional tag sequence. The other lines
1920 will be treated as ordinary lines in the
1921 paragraph.&lt;/P&gt;
1922 </pre>
1923
1924 <p>the lines of which happen to be broken as follows:
1925
1926 <pre>
1927 THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
1928 will be broken into several lines. The first
1929 line will be identified by a fictional tag
1930 sequence. The other lines will be treated as
1931 ordinary lines in the paragraph.
1932 </pre>
1933
1934 <p>This paragraph might be "rewritten" by user agents to include the
1935 <em>fictional tag sequence</em> for <code>::first-line</code>. This
1936 fictional tag sequence helps to show how properties are inherited.</p>
1937
1938 <pre>
1939 &lt;P&gt;<b>&lt;P::first-line&gt;</b> This is a somewhat long HTML
1940 paragraph that <b>&lt;/P::first-line&gt;</b> will be broken into several
1941 lines. The first line will be identified
1942 by a fictional tag sequence. The other lines
1943 will be treated as ordinary lines in the
1944 paragraph.&lt;/P&gt;
1945 </pre>
1946
1947 <p>If a pseudo-element breaks up a real element, the desired effect
1948 can often be described by a fictional tag sequence that closes and
1949 then re-opens the element. Thus, if we mark up the previous paragraph
1950 with a <code>span</code> element:</p>
1951
1952 <pre>
1953 &lt;P&gt;<b>&lt;SPAN class="test"&gt;</b> This is a somewhat long HTML
1954 paragraph that will be broken into several
1955 lines.<b>&lt;/SPAN&gt;</b> The first line will be identified
1956 by a fictional tag sequence. The other lines
1957 will be treated as ordinary lines in the
1958 paragraph.&lt;/P&gt;
1959 </pre>
1960
1961 <p>the user agent could simulate start and end tags for
1962 <code>span</code> when inserting the fictional tag sequence for
1963 <code>::first-line</code>.
1964
1965 <pre>
1966 &lt;P&gt;&lt;P::first-line&gt;<b>&lt;SPAN class="test"&gt;</b> This is a
1967 somewhat long HTML
1968 paragraph that will <b>&lt;/SPAN&gt;</b>&lt;/P::first-line&gt;<b>&lt;SPAN class= "test"&gt;</b> be
1969 broken into several
1970 lines.<b>&lt;/SPAN&gt;</b> The first line will be identified
1971 by a fictional tag sequence. The other lines
1972 will be treated as ordinary lines in the
1973 paragraph.&lt;/P&gt;
1974 </pre>
1975
1976 <p>In CSS, the <code>::first-line</code> pseudo-element can only be
1977 attached to a block-level element, an inline-block, a table-caption,
1978 or a table-cell.</p>
1979
1980 <p><a name="first-formatted-line"></a>The "first formatted line" of an
1981 element may occur inside a
1982 block-level descendant in the same flow (i.e., a block-level
1983 descendant that is not positioned and not a float). E.g., the first
1984 line of the <code>div</code> in <code>&lt;DIV>&lt;P>This
1985 line...&lt;/P>&lt/DIV></code> is the first line of the <code>p</code> (assuming
1986 that both <code>p</code> and <code>div</code> are block-level).
1987
1988 <p>The first line of a table-cell or inline-block cannot be the first
1989 formatted line of an ancestor element. Thus, in <code>&lt;DIV&gt;&lt;P
1990 STYLE="display: inline-block">Hello&lt;BR&gt;Goodbye&lt;/P&gt;
1991 etcetera&lt;/DIV&gt;</code> the first formatted line of the
1992 <code>div</code> is not the line "Hello".
1993
1994 <p class="note">Note that the first line of the <code>p</code> in this
1995 fragment: <code>&lt;p&gt&lt;br&gt;First...</code> doesn't contain any
1996 letters (assuming the default style for <code>br</code> in HTML
1997 4). The word "First" is not on the first formatted line.
1998
1999 <p>A UA should act as if the fictional start tags of the
2000 <code>::first-line</code> pseudo-elements were nested just inside the
2001 innermost enclosing block-level element. (Since CSS1 and CSS2 were
2002 silent on this case, authors should not rely on this behavior.) Here
2003 is an example. The fictional tag sequence for</p>
2004
2005 <pre>
2006 &lt;DIV>
2007 &lt;P>First paragraph&lt;/P>
2008 &lt;P>Second paragraph&lt;/P>
2009 &lt;/DIV>
2010 </pre>
2011
2012 <p>is</p>
2013
2014 <pre>
2015 &lt;DIV>
2016 &lt;P>&lt;DIV::first-line>&lt;P::first-line>First paragraph&lt;/P::first-line> &lt;/DIV::first-line>&lt;/P>
2017 &lt;P>&lt;P::first-line>Second paragraph&lt;/P::first-line>&lt;/P>
2018 &lt;/DIV>
2019 </pre>
2020
2021 <p>The <code>::first-line</code> pseudo-element is similar to an
2022 inline-level element, but with certain restrictions. In CSS, the
2023 following properties apply to a <code>::first-line</code>
2024 pseudo-element: font properties, color property, background
2025 properties, 'word-spacing', 'letter-spacing', 'text-decoration',
2026 'vertical-align', 'text-transform', 'line-height'. UAs may apply other
2027 properties as well.</p>
2028
2029
2030 <h4><a name=first-letter>7.2. The ::first-letter pseudo-element</a></h4>
2031
2032 <p>The <code>::first-letter</code> pseudo-element represents the first
2033 letter of the first line of a block, if it is not preceded by any
2034 other content (such as images or inline tables) on its line. The
2035 ::first-letter pseudo-element may be used for "initial caps" and "drop
2036 caps", which are common typographical effects. This type of initial
2037 letter is similar to an inline-level element if its 'float' property
2038 is 'none'; otherwise, it is similar to a floated element.</p>
2039
2040 <p>In CSS, these are the properties that apply to <code>::first-letter</code>
2041 pseudo-elements: font properties, 'text-decoration', 'text-transform',
2042 'letter-spacing', 'word-spacing' (when appropriate), 'line-height',
2043 'float', 'vertical-align' (only if 'float' is 'none'), margin
2044 properties, padding properties, border properties, color property,
2045 background properties. UAs may apply other properties as well. To
2046 allow UAs to render a typographically correct drop cap or initial cap,
2047 the UA may choose a line-height, width and height based on the shape
2048 of the letter, unlike for normal elements.</p>
2049
2050 <div class="example">
2051 <p>Example:</p>
2052 <p>This example shows a possible rendering of an initial cap. Note
2053 that the 'line-height' that is inherited by the <code>::first-letter</code>
2054 pseudo-element is 1.1, but the UA in this example has computed the
2055 height of the first letter differently, so that it doesn't cause any
2056 unnecessary space between the first two lines. Also note that the
2057 fictional start tag of the first letter is inside the <span>span</span>, and thu s
2058 the font weight of the first letter is normal, not bold as the <span>span</span> :
2059 <pre>
2060 p { line-height: 1.1 }
2061 p::first-letter { font-size: 3em; font-weight: normal }
2062 span { font-weight: bold }
2063 ...
2064 &lt;p>&lt;span>Het hemelsche&lt;/span> gerecht heeft zich ten lange lesten&lt;br >
2065 Erbarremt over my en mijn benaeuwde vesten&lt;br>
2066 En arme burgery, en op mijn volcx gebed&lt;br>
2067 En dagelix geschrey de bange stad ontzet.
2068 </pre>
2069 <div class="figure">
2070 <p><img src="initial-cap.png" alt="Image illustrating the ::first-letter pseudo- element">
2071 </div>
2072 </div>
2073
2074 <div class="example">
2075 <p>The following CSS will make a drop cap initial letter span about two lines:</ p>
2076
2077 <pre>
2078 &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
2079 &lt;HTML&gt;
2080 &lt;HEAD&gt;
2081 &lt;TITLE&gt;Drop cap initial letter&lt;/TITLE&gt;
2082 &lt;STYLE type="text/css"&gt;
2083 P { font-size: 12pt; line-height: 1.2 }
2084 P::first-letter { font-size: 200%; font-weight: bold; float: left }
2085 SPAN { text-transform: uppercase }
2086 &lt;/STYLE&gt;
2087 &lt;/HEAD&gt;
2088 &lt;BODY&gt;
2089 &lt;P&gt;&lt;SPAN&gt;The first&lt;/SPAN&gt; few words of an article
2090 in The Economist.&lt;/P&gt;
2091 &lt;/BODY&gt;
2092 &lt;/HTML&gt;
2093 </pre>
2094
2095 <p>This example might be formatted as follows:</p>
2096
2097 <div class="figure">
2098 <P><img src="first-letter.gif" alt="Image illustrating the combined effect of th e ::first-letter and ::first-line pseudo-elements"></p>
2099 </div>
2100
2101 <p>The <span class="index-inst" title="fictional tag
2102 sequence">fictional tag sequence</span> is:</p>
2103
2104 <pre>
2105 &lt;P&gt;
2106 &lt;SPAN&gt;
2107 &lt;P::first-letter&gt;
2108 T
2109 &lt;/P::first-letter&gt;he first
2110 &lt;/SPAN&gt;
2111 few words of an article in the Economist.
2112 &lt;/P&gt;
2113 </pre>
2114
2115 <p>Note that the <code>::first-letter</code> pseudo-element tags abut
2116 the content (i.e., the initial character), while the ::first-line
2117 pseudo-element start tag is inserted right after the start tag of the
2118 block element.</p> </div>
2119
2120 <p>In order to achieve traditional drop caps formatting, user agents
2121 may approximate font sizes, for example to align baselines. Also, the
2122 glyph outline may be taken into account when formatting.</p>
2123
2124 <p>Punctuation (i.e, characters defined in Unicode in the "open" (Ps),
2125 "close" (Pe), "initial" (Pi). "final" (Pf) and "other" (Po)
2126 punctuation classes), that precedes or follows the first letter should
2127 be included. <a href="#refsUNICODE">[UNICODE]</a></p>
2128
2129 <div class="figure">
2130 <P><img src="first-letter2.gif" alt="Quotes that precede the
2131 first letter should be included."></p>
2132 </div>
2133
2134 <p>The <code>::first-letter</code> also applies if the first letter is
2135 in fact a digit, e.g., the "6" in "67 million dollars is a lot of
2136 money."</p>
2137
2138 <p>In CSS, the <code>::first-letter</code> pseudo-element applies to
2139 block, list-item, table-cell, table-caption, and inline-block
2140 elements. <span class="note">A future version of this specification
2141 may allow this pesudo-element to apply to more element
2142 types.</span></p>
2143
2144 <p>The <code>::first-letter</code> pseudo-element can be used with all
2145 such elements that contain text, or that have a descendant in the same
2146 flow that contains text. A UA should act as if the fictional start tag
2147 of the ::first-letter pseudo-element is just before the first text of
2148 the element, even if that first text is in a descendant.</p>
2149
2150 <div class="example">
2151 <p>Example:</p>
2152 <p>The fictional tag sequence for this HTMLfragment:
2153 <pre>&lt;div>
2154 &lt;p>The first text.</pre>
2155 <p>is:
2156 <pre>&lt;div>
2157 &lt;p>&lt;div::first-letter>&lt;p::first-letter>T&lt;/...>&lt;/...>he first text .</pre>
2158 </div>
2159
2160 <p>The first letter of a table-cell or inline-block cannot be the
2161 first letter of an ancestor element. Thus, in <code>&lt;DIV&gt;&lt;P
2162 STYLE="display: inline-block">Hello&lt;BR&gt;Goodbye&lt;/P&gt;
2163 etcetera&lt;/DIV&gt;</code> the first letter of the <code>div</code> is not the
2164 letter "H". In fact, the <code>div</code> doesn't have a first letter.
2165
2166 <p>The first letter must occur on the <a
2167 href="#first-formatted-line">first formatted line.</a> For example, in
2168 this fragment: <code>&lt;p&gt&lt;br&gt;First...</code> the first line
2169 doesn't contain any letters and <code>::first-letter</code> doesn't
2170 match anything (assuming the default style for <code>br</code> in HTML
2171 4). In particular, it does not match the "F" of "First."
2172
2173 <p>In CSS, if an element is a list item ('display: list-item'), the
2174 <code>::first-letter</code> applies to the first letter in the
2175 principal box after the marker. UAs may ignore
2176 <code>::first-letter</code> on list items with 'list-style-position:
2177 inside'. If an element has <code>::before</code> or
2178 <code>::after</code> content, the <code>::first-letter</code> applies
2179 to the first letter of the element <em>including</em> that content.
2180
2181 <div class="example">
2182 <p>Example:</p>
2183 <p>After the rule 'p::before {content: "Note: "}', the selector
2184 'p::first-letter' matches the "N" of "Note".</p>
2185 </div>
2186
2187 <p>Some languages may have specific rules about how to treat certain
2188 letter combinations. In Dutch, for example, if the letter combination
2189 "ij" appears at the beginning of a word, both letters should be
2190 considered within the <code>::first-letter</code> pseudo-element.
2191
2192 <p>If the letters that would form the ::first-letter are not in the
2193 same element, such as "'T" in <code>&lt;p>'&lt;em>T...</code>, the UA
2194 may create a ::first-letter pseudo-element from one of the elements,
2195 both elements, or simply not create a pseudo-element.</p>
2196
2197 <p>Similarly, if the first letter(s) of the block are not at the start
2198 of the line (for example due to bidirectional reordering), then the UA
2199 need not create the pseudo-element(s).
2200
2201 <div class="example">
2202 <p>Example:</p>
2203 <p><a name="overlapping-example">The following example</a> illustrates
2204 how overlapping pseudo-elements may interact. The first letter of
2205 each P element will be green with a font size of '24pt'. The rest of
2206 the first formatted line will be 'blue' while the rest of the
2207 paragraph will be 'red'.</p>
2208
2209 <pre>p { color: red; font-size: 12pt }
2210 p::first-letter { color: green; font-size: 200% }
2211 p::first-line { color: blue }
2212
2213 &lt;P&gt;Some text that ends up on two lines&lt;/P&gt;</pre>
2214
2215 <p>Assuming that a line break will occur before the word "ends", the
2216 <span class="index-inst" title="fictional tag sequence">fictional tag
2217 sequence</span> for this fragment might be:</p>
2218
2219 <pre>&lt;P&gt;
2220 &lt;P::first-line&gt;
2221 &lt;P::first-letter&gt;
2222 S
2223 &lt;/P::first-letter&gt;ome text that
2224 &lt;/P::first-line&gt;
2225 ends up on two lines
2226 &lt;/P&gt;</pre>
2227
2228 <p>Note that the <code>::first-letter</code> element is inside the <code>::first -line</code>
2229 element. Properties set on <code>::first-line</code> are inherited by
2230 <code>::first-letter</code>, but are overridden if the same property is set on
2231 <code>::first-letter</code>.</p>
2232 </div>
2233
2234
2235 <h4><a name=UIfragments>7.3.</a> <a name=selection>The ::selection pseudo-elemen t</a></h4>
2236
2237 <p>The <code>::selection</code> pseudo-element applies to the portion
2238 of a document that has been highlighted by the user. This also
2239 applies, for example, to selected text within an editable text
2240 field. This pseudo-element should not be confused with the <code><a
2241 href="#checked">:checked</a></code> pseudo-class (which used to be
2242 named <code>:selected</code>)
2243
2244 <p>Although the <code>::selection</code> pseudo-element is dynamic in
2245 nature, and is altered by user action, it is reasonable to expect that
2246 when a UA re-renders to a static medium (such as a printed page, see
2247 <a href="#refsCSS21">[CSS21]</a>) which was originally rendered to a
2248 dynamic medium (like screen), the UA may wish to transfer the current
2249 <code>::selection</code> state to that other medium, and have all the
2250 appropriate formatting and rendering take effect as well. This is not
2251 required &mdash; UAs may omit the <code>::selection</code>
2252 pseudo-element for static media.
2253
2254 <p>These are the CSS properties that apply to <code>::selection</code>
2255 pseudo-elements: color, background, cursor (optional), outline
2256 (optional). The computed value of the 'background-image' property on
2257 <code>::selection</code> may be ignored.
2258
2259
2260 <h4><a name=gen-content>7.4. The ::before and ::after pseudo-elements</a></h4>
2261
2262 <p>The <code>::before</code> and <code>::after</code> pseudo-elements
2263 can be used to describe generated content before or after an element's
2264 content. They are explained in CSS 2.1 <a
2265 href="#refsCSS21">[CSS21]</a>.</p>
2266
2267 <p>When the <code>::first-letter</code> and <code>::first-line</code>
2268 pseudo-elements are combined with <code>::before</code> and
2269 <code>::after</code>, they apply to the first letter or line of the
2270 element including the inserted text.</p>
2271
2272 <h2><a name=combinators>8. Combinators</a></h2>
2273
2274 <h3><a name=descendant-combinators>8.1. Descendant combinator</a></h3>
2275
2276 <p>At times, authors may want selectors to describe an element that is
2277 the descendant of another element in the document tree (e.g., "an
2278 <code>EM</code> element that is contained within an <code>H1</code>
2279 element"). Descendant combinators express such a relationship. A
2280 descendant combinator is <a href="#whitespace">white space</a> that
2281 separates two sequences of simple selectors. A selector of the form
2282 "<code>A B</code>" represents an element <code>B</code> that is an
2283 arbitrary descendant of some ancestor element <code>A</code>.
2284
2285 <div class="example">
2286 <p>Examples:</p>
2287 <p>For example, consider the following selector:</p>
2288 <pre>h1 em</pre>
2289 <p>It represents an <code>em</code> element being the descendant of
2290 an <code>h1</code> element. It is a correct and valid, but partial,
2291 description of the following fragment:</p>
2292 <pre>&lt;h1&gt;This &lt;span class="myclass"&gt;headline
2293 is &lt;em&gt;very&lt;/em&gt; important&lt;/span&gt;&lt;/h1&gt;</pre>
2294 <p>The following selector:</p>
2295 <pre>div * p</pre>
2296 <p>represents a <code>p</code> element that is a grandchild or later
2297 descendant of a <code>div</code> element. Note the whitespace on
2298 either side of the "*" is not part of the universal selector; the
2299 whitespace is a combinator indicating that the DIV must be the
2300 ancestor of some element, and that that element must be an ancestor
2301 of the P.</p>
2302 <p>The following selector, which combines descendant combinators and
2303 <a href="#attribute-selectors">attribute selectors</a>, represents an
2304 element that (1) has the <code>href</code> attribute set and (2) is
2305 inside a <code>p</code> that is itself inside a <code>div</code>:</p>
2306 <pre>div p *[href]</pre>
2307 </div>
2308
2309 <h3><a name=child-combinators>8.2. Child combinators</a></h3>
2310
2311 <p>A <dfn>child combinator</dfn> describes a childhood relationship
2312 between two elements. A child combinator is made of the
2313 &quot;greater-than sign&quot; (<code>&gt;</code>) character and
2314 separates two sequences of simple selectors.
2315
2316
2317 <div class="example">
2318 <p>Examples:</p>
2319 <p>The following selector represents a <code>p</code> element that is
2320 child of <code>body</code>:</p>
2321 <pre>body &gt; p</pre>
2322 <p>The following example combines descendant combinators and child
2323 combinators.</p>
2324 <pre>div ol&gt;li p</pre><!-- LEAVE THOSE SPACES OUT! see below -->
2325 <p>It represents a <code>p</code> element that is a descendant of an
2326 <code>li</code> element; the <code>li</code> element must be the
2327 child of an <code>ol</code> element; the <code>ol</code> element must
2328 be a descendant of a <code>div</code>. Notice that the optional white
2329 space around the "&gt;" combinator has been left out.</p>
2330 </div>
2331
2332 <p>For information on selecting the first child of an element, please
2333 see the section on the <code><a
2334 href="#structural-pseudos">:first-child</a></code> pseudo-class
2335 above.</p>
2336
2337 <h3><a name=sibling-combinators>8.3. Sibling combinators</a></h3>
2338
2339 <p>There are two different sibling combinators: the adjacent sibling
2340 combinator and the general sibling combinator. In both cases,
2341 non-element nodes (e.g. text between elements) are ignored when
2342 considering adjacency of elements.</p>
2343
2344 <h4><a name=adjacent-sibling-combinators>8.3.1. Adjacent sibling combinator</a>< /h4>
2345
2346 <p>The adjacent sibling combinator is made of the &quot;plus
2347 sign&quot; (U+002B, <code>+</code>) character that separates two
2348 sequences of simple selectors. The elements represented by the two
2349 sequences share the same parent in the document tree and the element
2350 represented by the first sequence immediately precedes the element
2351 represented by the second one.</p>
2352
2353 <div class="example">
2354 <p>Examples:</p>
2355 <p>The following selector represents a <code>p</code> element
2356 immediately following a <code>math</code> element:</p>
2357 <pre>math + p</pre>
2358 <p>The following selector is conceptually similar to the one in the
2359 previous example, except that it adds an attribute selector &mdash; it
2360 adds a constraint to the <code>h1</code> element, that it must have
2361 <code>class="opener"</code>:</p>
2362 <pre>h1.opener + h2</pre>
2363 </div>
2364
2365
2366 <h4><a name=general-sibling-combinators>8.3.2. General sibling combinator</a></h 4>
2367
2368 <p>The general sibling combinator is made of the &quot;tilde&quot;
2369 (U+007E, <code>~</code>) character that separates two sequences of
2370 simple selectors. The elements represented by the two sequences share
2371 the same parent in the document tree and the element represented by
2372 the first sequence precedes (not necessarily immediately) the element
2373 represented by the second one.</p>
2374
2375 <div class="example">
2376 <p>Example:</p>
2377 <pre>h1 ~ pre</pre>
2378 <p>represents a <code>pre</code> element following an <code>h1</code>. It
2379 is a correct and valid, but partial, description of:</p>
2380 <pre>&lt;h1&gt;Definition of the function a&lt;/h1&gt;
2381 &lt;p&gt;Function a(x) has to be applied to all figures in the table.&lt;/p&gt;
2382 &lt;pre&gt;function a(x) = 12x/13.5&lt;/pre&gt;</pre>
2383 </div>
2384
2385 <h2><a name=specificity>9. Calculating a selector's specificity</a></h2>
2386
2387 <p>A selector's specificity is calculated as follows:</p>
2388
2389 <ul>
2390 <li>count the number of ID selectors in the selector (= a)</li>
2391 <li>count the number of class selectors, attributes selectors, and pseudo-clas ses in the selector (= b)</li>
2392 <li>count the number of element names in the selector (= c)</li>
2393 <li>ignore pseudo-elements</li>
2394 </ul>
2395
2396 <p>Selectors inside <a href="#negation">the negation pseudo-class</a>
2397 are counted like any other, but the negation itself does not count as
2398 a pseudo-class.</p>
2399
2400 <p>Concatenating the three numbers a-b-c (in a number system with a
2401 large base) gives the specificity.</p>
2402
2403 <div class="example">
2404 <p>Examples:</p>
2405 <pre>* /* a=0 b=0 c=0 -&gt; specificity = 0 */
2406 LI /* a=0 b=0 c=1 -&gt; specificity = 1 */
2407 UL LI /* a=0 b=0 c=2 -&gt; specificity = 2 */
2408 UL OL+LI /* a=0 b=0 c=3 -&gt; specificity = 3 */
2409 H1 + *[REL=up] /* a=0 b=1 c=1 -&gt; specificity = 11 */
2410 UL OL LI.red /* a=0 b=1 c=3 -&gt; specificity = 13 */
2411 LI.red.level /* a=0 b=2 c=1 -&gt; specificity = 21 */
2412 #x34y /* a=1 b=0 c=0 -&gt; specificity = 100 */
2413 #s12:not(FOO) /* a=1 b=0 c=1 -&gt; specificity = 101 */
2414 </pre>
2415 </div>
2416
2417 <p class="note"><strong>Note:</strong> the specificity of the styles
2418 specified in an HTML <code>style</code> attribute is described in CSS
2419 2.1. <a href="#refsCSS21">[CSS21]</a>.</p>
2420
2421 <h2><a name=w3cselgrammar>10. The grammar of Selectors</a></h2>
2422
2423 <h3><a name=grammar>10.1. Grammar</a></h3>
2424
2425 <p>The grammar below defines the syntax of Selectors. It is globally
2426 LL(1) and can be locally LL(2) (but note that most UA's should not use
2427 it directly, since it doesn't express the parsing conventions). The
2428 format of the productions is optimized for human consumption and some
2429 shorthand notations beyond Yacc (see <a href="#refsYACC">[YACC]</a>)
2430 are used:</p>
2431
2432 <ul>
2433 <li><b>*</b>: 0 or more
2434 <li><b>+</b>: 1 or more
2435 <li><b>?</b>: 0 or 1
2436 <li><b>|</b>: separates alternatives
2437 <li><b>[ ]</b>: grouping </li>
2438 </ul>
2439
2440 <p>The productions are:</p>
2441
2442 <pre>selectors_group
2443 : selector [ COMMA S* selector ]*
2444 ;
2445
2446 selector
2447 : simple_selector_sequence [ combinator simple_selector_sequence ]*
2448 ;
2449
2450 combinator
2451 /* combinators can be surrounded by white space */
2452 : PLUS S* | GREATER S* | TILDE S* | S+
2453 ;
2454
2455 simple_selector_sequence
2456 : [ type_selector | universal ]
2457 [ HASH | class | attrib | pseudo | negation ]*
2458 | [ HASH | class | attrib | pseudo | negation ]+
2459 ;
2460
2461 type_selector
2462 : [ namespace_prefix ]? element_name
2463 ;
2464
2465 namespace_prefix
2466 : [ IDENT | '*' ]? '|'
2467 ;
2468
2469 element_name
2470 : IDENT
2471 ;
2472
2473 universal
2474 : [ namespace_prefix ]? '*'
2475 ;
2476
2477 class
2478 : '.' IDENT
2479 ;
2480
2481 attrib
2482 : '[' S* [ namespace_prefix ]? IDENT S*
2483 [ [ PREFIXMATCH |
2484 SUFFIXMATCH |
2485 SUBSTRINGMATCH |
2486 '=' |
2487 INCLUDES |
2488 DASHMATCH ] S* [ IDENT | STRING ] S*
2489 ]? ']'
2490 ;
2491
2492 pseudo
2493 /* '::' starts a pseudo-element, ':' a pseudo-class */
2494 /* Exceptions: :first-line, :first-letter, :before and :after. */
2495 /* Note that pseudo-elements are restricted to one per selector and */
2496 /* occur only in the last simple_selector_sequence. */
2497 : ':' ':'? [ IDENT | functional_pseudo ]
2498 ;
2499
2500 functional_pseudo
2501 : FUNCTION S* expression ')'
2502 ;
2503
2504 expression
2505 /* In CSS3, the expressions are identifiers, strings, */
2506 /* or of the form "an+b" */
2507 : [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
2508 ;
2509
2510 negation
2511 : NOT S* negation_arg S* ')'
2512 ;
2513
2514 negation_arg
2515 : type_selector | universal | HASH | class | attrib | pseudo
2516 ;</pre>
2517
2518
2519 <h3><a name=lex>10.2. Lexical scanner</a></h3>
2520
2521 <p>The following is the <a name=x3>tokenizer</a>, written in Flex (see
2522 <a href="#refsFLEX">[FLEX]</a>) notation. The tokenizer is
2523 case-insensitive.</p>
2524
2525 <p>The two occurrences of "\377" represent the highest character
2526 number that current versions of Flex can deal with (decimal 255). They
2527 should be read as "\4177777" (decimal 1114111), which is the highest
2528 possible code point in Unicode/ISO-10646. <a
2529 href="#refsUNICODE">[UNICODE]</a></p>
2530
2531 <pre>%option case-insensitive
2532
2533 ident [-]?{nmstart}{nmchar}*
2534 name {nmchar}+
2535 nmstart [_a-z]|{nonascii}|{escape}
2536 nonascii [^\0-\177]
2537 unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
2538 escape {unicode}|\\[^\n\r\f0-9a-f]
2539 nmchar [_a-z0-9-]|{nonascii}|{escape}
2540 num [0-9]+|[0-9]*\.[0-9]+
2541 string {string1}|{string2}
2542 string1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*\"
2543 string2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*\'
2544 invalid {invalid1}|{invalid2}
2545 invalid1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*
2546 invalid2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*
2547 nl \n|\r\n|\r|\f
2548 w [ \t\r\n\f]*
2549
2550 %%
2551
2552 [ \t\r\n\f]+ return S;
2553
2554 "~=" return INCLUDES;
2555 "|=" return DASHMATCH;
2556 "^=" return PREFIXMATCH;
2557 "$=" return SUFFIXMATCH;
2558 "*=" return SUBSTRINGMATCH;
2559 {ident} return IDENT;
2560 {string} return STRING;
2561 {ident}"(" return FUNCTION;
2562 {num} return NUMBER;
2563 "#"{name} return HASH;
2564 {w}"+" return PLUS;
2565 {w}"&gt;" return GREATER;
2566 {w}"," return COMMA;
2567 {w}"~" return TILDE;
2568 ":not(" return NOT;
2569 @{ident} return ATKEYWORD;
2570 {invalid} return INVALID;
2571 {num}% return PERCENTAGE;
2572 {num}{ident} return DIMENSION;
2573 "&lt;!--" return CDO;
2574 "--&gt;" return CDC;
2575
2576 "url("{w}{string}{w}")" return URI;
2577 "url("{w}([!#$%&*-~]|{nonascii}|{escape})*{w}")" return URI;
2578 U\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})? return UNICODE_RANGE;
2579
2580 \/\*[^*]*\*+([^/*][^*]*\*+)*\/ /* ignore comments */
2581
2582 . return *yytext;</pre>
2583
2584
2585
2586 <h2><a name=downlevel>11. Namespaces and down-level clients</a></h2>
2587
2588 <p>An important issue is the interaction of CSS selectors with XML
2589 documents in web clients that were produced prior to this
2590 document. Unfortunately, due to the fact that namespaces must be
2591 matched based on the URI which identifies the namespace, not the
2592 namespace prefix, some mechanism is required to identify namespaces in
2593 CSS by their URI as well. Without such a mechanism, it is impossible
2594 to construct a CSS style sheet which will properly match selectors in
2595 all cases against a random set of XML documents. However, given
2596 complete knowledge of the XML document to which a style sheet is to be
2597 applied, and a limited use of namespaces within the XML document, it
2598 is possible to construct a style sheet in which selectors would match
2599 elements and attributes correctly.</p>
2600
2601 <p>It should be noted that a down-level CSS client will (if it
2602 properly conforms to CSS forward compatible parsing rules) ignore all
2603 <code>@namespace</code> at-rules, as well as all style rules that make
2604 use of namespace qualified element type or attribute selectors. The
2605 syntax of delimiting namespace prefixes in CSS was deliberately chosen
2606 so that down-level CSS clients would ignore the style rules rather
2607 than possibly match them incorrectly.</p>
2608
2609 <p>The use of default namespaces in CSS makes it possible to write
2610 element type selectors that will function in both namespace aware CSS
2611 clients as well as down-level clients. It should be noted that
2612 down-level clients may incorrectly match selectors against XML
2613 elements in other namespaces.</p>
2614
2615 <p>The following are scenarios and examples in which it is possible to
2616 construct style sheets which would function properly in web clients
2617 that do not implement this proposal.</p>
2618
2619 <ol>
2620 <li>
2621
2622 <p>The XML document does not use namespaces.</p>
2623
2624 <ul>
2625
2626 <li>In this case, it is obviously not necessary to declare or use
2627 namespaces in the style sheet. Standard CSS element type and
2628 attribute selectors will function adequately in a down-level
2629 client.</li>
2630
2631 <li>In a CSS namespace aware client, the default behavior of
2632 element selectors matching without regard to namespace will
2633 function properly against all elements, since no namespaces are
2634 present. However, the use of specific element type selectors that
2635 match only elements that have no namespace ("<code>|name</code>")
2636 will guarantee that selectors will match only XML elements that do
2637 not have a declared namespace. </li>
2638
2639 </ul>
2640
2641 </li>
2642
2643 <li>
2644
2645 <p>The XML document defines a single, default namespace used
2646 throughout the document. No namespace prefixes are used in element
2647 names.</p>
2648
2649 <ul>
2650
2651 <li>In this case, a down-level client will function as if
2652 namespaces were not used in the XML document at all. Standard CSS
2653 element type and attribute selectors will match against all
2654 elements. </li>
2655
2656 </ul>
2657
2658 </li>
2659
2660 <li>
2661
2662 <p>The XML document does <b>not</b> use a default namespace, all
2663 namespace prefixes used are known to the style sheet author, and
2664 there is a direct mapping between namespace prefixes and namespace
2665 URIs. (A given prefix may only be mapped to one namespace URI
2666 throughout the XML document; there may be multiple prefixes mapped
2667 to the same URI).</p>
2668
2669 <ul>
2670
2671 <li>In this case, the down-level client will view and match
2672 element type and attribute selectors based on their fully
2673 qualified name, not the local part as outlined in the <a
2674 href="#typenmsp">Type selectors and Namespaces</a> section. CSS
2675 selectors may be declared using an escaped colon "<code>\:</code>"
2676 to describe the fully qualified names, e.g.
2677 "<code>html\:h1</code>" will match
2678 <code>&lt;html:h1&gt;</code>. Selectors using the qualified name
2679 will only match XML elements that use the same prefix. Other
2680 namespace prefixes used in the XML that are mapped to the same URI
2681 will not match as expected unless additional CSS style rules are
2682 declared for them.</li>
2683
2684 <li>Note that selectors declared in this fashion will
2685 <em>only</em> match in down-level clients. A CSS namespace aware
2686 client will match element type and attribute selectors based on
2687 the name's local part. Selectors declared with the fully
2688 qualified name will not match (unless there is no namespace prefix
2689 in the fully qualified name).</li>
2690
2691 </ul>
2692
2693 </li>
2694
2695 </ol>
2696
2697 <p>In other scenarios: when the namespace prefixes used in the XML are
2698 not known in advance by the style sheet author; or a combination of
2699 elements with no namespace are used in conjunction with elements using
2700 a default namespace; or the same namespace prefix is mapped to
2701 <em>different</em> namespace URIs within the same document, or in
2702 different documents; it is impossible to construct a CSS style sheet
2703 that will function properly against all elements in those documents,
2704 unless, the style sheet is written using a namespace URI syntax (as
2705 outlined in this document or similar) and the document is processed by
2706 a CSS and XML namespace aware client.</p>
2707
2708 <h2><a name=profiling>12. Profiles</a></h2>
2709
2710 <p>Each specification using Selectors must define the subset of W3C
2711 Selectors it allows and excludes, and describe the local meaning of
2712 all the components of that subset.</p>
2713
2714 <p>Non normative examples:
2715
2716 <div class="profile">
2717 <table class="tprofile">
2718 <tbody>
2719 <tr>
2720 <th class="title" colspan=2>Selectors profile</th></tr>
2721 <tr>
2722 <th>Specification</th>
2723 <td>CSS level 1</td></tr>
2724 <tr>
2725 <th>Accepts</th>
2726 <td>type selectors<br>class selectors<br>ID selectors<br>:link,
2727 :visited and :active pseudo-classes<br>descendant combinator
2728 <br>::first-line and ::first-letter pseudo-elements</td></tr>
2729 <tr>
2730 <th>Excludes</th>
2731 <td>
2732
2733 <p>universal selector<br>attribute selectors<br>:hover and :focus
2734 pseudo-classes<br>:target pseudo-class<br>:lang() pseudo-class<br>all UI
2735 element states pseudo-classes<br>all structural
2736 pseudo-classes<br>negation pseudo-class<br>all
2737 UI element fragments pseudo-elements<br>::before and ::after
2738 pseudo-elements<br>child combinators<br>sibling combinators
2739
2740 <p>namespaces</td></tr>
2741 <tr>
2742 <th>Extra constraints</th>
2743 <td>only one class selector allowed per sequence of simple
2744 selectors</td></tr></tbody></table><br><br>
2745 <table class="tprofile">
2746 <tbody>
2747 <tr>
2748 <th class="title" colspan=2>Selectors profile</th></tr>
2749 <tr>
2750 <th>Specification</th>
2751 <td>CSS level 2</td></tr>
2752 <tr>
2753 <th>Accepts</th>
2754 <td>type selectors<br>universal selector<br>attribute presence and
2755 values selectors<br>class selectors<br>ID selectors<br>:link, :visited,
2756 :active, :hover, :focus, :lang() and :first-child pseudo-classes
2757 <br>descendant combinator<br>child combinator<br>adjacent sibling
2758 combinator<br>::first-line and ::first-letter pseudo-elements<br>::before
2759 and ::after pseudo-elements</td></tr>
2760 <tr>
2761 <th>Excludes</th>
2762 <td>
2763
2764 <p>content selectors<br>substring matching attribute
2765 selectors<br>:target pseudo-classes<br>all UI element
2766 states pseudo-classes<br>all structural pseudo-classes other
2767 than :first-child<br>negation pseudo-class<br>all UI element
2768 fragments pseudo-elements<br>general sibling combinators
2769
2770 <p>namespaces</td></tr>
2771 <tr>
2772 <th>Extra constraints</th>
2773 <td>more than one class selector per sequence of simple selectors (CSS1
2774 constraint) allowed</td></tr></tbody></table>
2775
2776 <p>In CSS, selectors express pattern matching rules that determine which style
2777 rules apply to elements in the document tree.
2778
2779 <p>The following selector (CSS level 2) will <b>match</b> all anchors <code>a</c ode>
2780 with attribute <code>name</code> set inside a section 1 header <code>h1</code>:
2781 <pre>h1 a[name]</pre>
2782
2783 <p>All CSS declarations attached to such a selector are applied to elements
2784 matching it. </div>
2785
2786 <div class="profile">
2787 <table class="tprofile">
2788 <tbody>
2789 <tr>
2790 <th class="title" colspan=2>Selectors profile</th></tr>
2791 <tr>
2792 <th>Specification</th>
2793 <td>STTS 3</td>
2794 </tr>
2795 <tr>
2796 <th>Accepts</th>
2797 <td>
2798
2799 <p>type selectors<br>universal selectors<br>attribute selectors<br>class
2800 selectors<br>ID selectors<br>all structural pseudo-classes<br>
2801 all combinators
2802
2803 <p>namespaces</td></tr>
2804 <tr>
2805 <th>Excludes</th>
2806 <td>non-accepted pseudo-classes<br>pseudo-elements<br></td></tr>
2807 <tr>
2808 <th>Extra constraints</th>
2809 <td>some selectors and combinators are not allowed in fragment
2810 descriptions on the right side of STTS declarations.</td></tr></tbody></ta ble>
2811 <form>
2812 <input type="text" name="test10"/>
2813 <input type="text" name="foo"/>
2814 <input type="text" name="foo"/>
2815 <input type="text" name="foo"/>
2816 <input type="text" name="foo"/>
2817 <input type="text" name="foo"/>
2818 <input type="text" name="foo"/>
2819 <input type="text" name="foo"/>
2820 <input type="text" name="foo"/>
2821 <input type="text" name="foo"/>
2822 <input type="text" name="foo"/>
2823 <input type="text" name="foo"/>
2824 <input type="text" name="foo"/>
2825 <input type="text" name="foo"/>
2826 <input type="text" name="foo"/>
2827 <input type="text" name="foo"/>
2828 <input type="text" name="foo"/>
2829 <input type="text" name="foo"/>
2830 <input type="text" name="foo"/>
2831 <input type="text" name="foo"/>
2832 <input type="text" name="foo"/>
2833 <input type="text" name="foo"/>
2834 <input type="text" name="foo"/>
2835 <input type="text" name="foo"/>
2836 <input type="text" name="foo"/>
2837 </form>
2838
2839 <p>Selectors can be used in STTS 3 in two different
2840 manners:
2841 <ol>
2842 <li>a selection mechanism equivalent to CSS selection mechanism: declarations
2843 attached to a given selector are applied to elements matching that selector,
2844 <li>fragment descriptions that appear on the right side of declarations.
2845 </li></ol></div>
2846
2847 <h2><a name=Conformance></a>13. Conformance and requirements</h2>
2848
2849 <p>This section defines conformance with the present specification only.
2850
2851 <p>The inability of a user agent to implement part of this specification due to
2852 the limitations of a particular device (e.g., non interactive user agents will
2853 probably not implement dynamic pseudo-classes because they make no sense without
2854 interactivity) does not imply non-conformance.
2855
2856 <p>All specifications reusing Selectors must contain a <a
2857 href="#profiling">Profile</a> listing the
2858 subset of Selectors it accepts or excludes, and describing the constraints
2859 it adds to the current specification.
2860
2861 <p>Invalidity is caused by a parsing error, e.g. an unrecognized token or a toke n
2862 which is not allowed at the current parsing point.
2863
2864 <p>User agents must observe the rules for handling parsing errors:
2865 <ul>
2866 <li>a simple selector containing an undeclared namespace prefix is invalid</li >
2867 <li>a selector containing an invalid simple selector, an invalid combinator
2868 or an invalid token is invalid. </li>
2869 <li>a group of selectors containing an invalid selector is invalid.</li>
2870 </ul>
2871
2872 <p class="foo test10 bar">Specifications reusing Selectors must define how to ha ndle parsing
2873 errors. (In the case of CSS, the entire rule in which the selector is
2874 used is dropped.)</p>
2875
2876 <!-- Apparently all these references are out of date:
2877 <p>Implementations of this specification must behave as
2878 "recipients of text data" as defined by <a href="#refsCWWW">[CWWW]</a>
2879 when parsing selectors and attempting matches. (In particular,
2880 implementations must assume the data is normalized and must not
2881 normalize it.) Normative rules for matching strings are defined in
2882 <a href="#refsCWWW">[CWWW]</a> and <a
2883 href="#refsUNICODE">[UNICODE]</a> and apply to implementations of this
2884 specification.</p>-->
2885
2886 <h2><a name=Tests></a>14. Tests</h2>
2887
2888 <p>This specification has <a
2889 href="http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/">a test
2890 suite</a> allowing user agents to verify their basic conformance to
2891 the specification. This test suite does not pretend to be exhaustive
2892 and does not cover all possible combined cases of Selectors.</p>
2893
2894 <h2><a name=ACKS></a>15. Acknowledgements</h2>
2895
2896 <p>The CSS working group would like to thank everyone who has sent
2897 comments on this specification over the years.</p>
2898
2899 <p>The working group would like to extend special thanks to Donna
2900 McManus, Justin Baker, Joel Sklar, and Molly Ives Brower who perfermed
2901 the final editorial review.</p>
2902
2903 <h2><a name=references>16. References</a></h2>
2904
2905 <dl class="refs">
2906
2907 <dt>[CSS1]
2908 <dd><a name=refsCSS1></a> Bert Bos, H&aring;kon Wium Lie; "<cite>Cascading Sty le Sheets, level 1</cite>", W3C Recommendation, 17 Dec 1996, revised 11 Jan 1999
2909 <dd>(<code><a href="http://www.w3.org/TR/REC-CSS1">http://www.w3.org/TR/REC-CS S1</a></code>)
2910
2911 <dt>[CSS21]
2912 <dd><a name=refsCSS21></a> Bert Bos, Tantek &Ccedil;elik, Ian Hickson, H&aring ;kon Wium Lie, editors; "<cite>Cascading Style Sheets, level 2 revision 1</cite> ", W3C Working Draft, 13 June 2005
2913 <dd>(<code><a href="http://www.w3.org/TR/CSS21">http://www.w3.org/TR/CSS21</a> </code>)
2914
2915 <dt>[CWWW]
2916 <dd><a name=refsCWWW></a> Martin J. D&uuml;rst, Fran&ccedil;ois Yergeau, Misha Wolf, Asmus Freytag, Tex Texin, editors; "<cite>Character Model for the World W ide Web</cite>", W3C Recommendation, 15 February 2005
2917 <dd>(<code><a href="http://www.w3.org/TR/charmod/">http://www.w3.org/TR/charmo d/</a></code>)
2918
2919 <dt>[FLEX]
2920 <dd><a name="refsFLEX"></a> "<cite>Flex: The Lexical Scanner Generator</cite>" , Version 2.3.7, ISBN 1882114213
2921
2922 <dt>[HTML4]
2923 <dd><a name="refsHTML4"></a> Dave Ragget, Arnaud Le Hors, Ian Jacobs, editors; "<cite>HTML 4.01 Specification</cite>", W3C Recommendation, 24 December 1999
2924 <dd>(<a href="http://www.w3.org/TR/html4/"><code>http://www.w3.org/TR/html4/</ code></a>)
2925
2926 <dt>[MATH]
2927 <dd><a name="refsMATH"></a> Patrick Ion, Robert Miner, editors; "<cite>Mathema tical Markup Language (MathML) 1.01</cite>", W3C Recommendation, revision of 7 J uly 1999
2928 <dd>(<code><a href="http://www.w3.org/TR/REC-MathML/">http://www.w3.org/TR/REC -MathML/</a></code>)
2929
2930 <dt>[RFC3066]
2931 <dd><a name="refsRFC3066"></a> H. Alvestrand; "<cite>Tags for the Identificati on of Languages</cite>", Request for Comments 3066, January 2001
2932 <dd>(<a href="http://www.ietf.org/rfc/rfc3066.txt"><code>http://www.ietf.org/r fc/rfc3066.txt</code></a>)
2933
2934 <dt>[STTS]
2935 <dd><a name=refsSTTS></a> Daniel Glazman; "<cite>Simple Tree Transformation Sh eets 3</cite>", Electricit&eacute; de France, submission to the W3C, 11 November 1998
2936 <dd>(<code><a href="http://www.w3.org/TR/NOTE-STTS3">http://www.w3.org/TR/NOTE -STTS3</a></code>)
2937
2938 <dt>[SVG]
2939 <dd><a name="refsSVG"></a> Jon Ferraiolo, &#34276;&#27810; &#28147;, Dean Jack son, editors; "<cite>Scalable Vector Graphics (SVG) 1.1 Specification</cite>", W 3C Recommendation, 14 January 2003
2940 <dd>(<code><a href="http://www.w3.org/TR/SVG/">http://www.w3.org/TR/SVG/</a></ code>)
2941
2942 <dt>[UNICODE]</dt>
2943 <dd><a name="refsUNICODE"></a> <cite><a
2944 href="http://www.unicode.org/versions/Unicode4.1.0/">The Unicode Standard, Ve rsion 4.1</a></cite>, The Unicode Consortium. Boston, MA, Addison-Wesley, March 2005. ISBN 0-321-18578-1, as amended by <a href="http://www.unicode.org/versions /Unicode4.0.1/">Unicode 4.0.1</a> and <a href="http://www.unicode.org/versions/U nicode4.1.0/">Unicode 4.1.0</a>.
2945 <dd>(<code><a href="http://www.unicode.org/versions/">http://www.unicode.org/v ersions/</a></code>)</dd>
2946
2947 <dt>[XML10]
2948 <dd><a name="refsXML10"></a> Tim Bray, Jean Paoli, C. M. Sperberg-McQueen, Eve Maler, Fran&ccedil;ois Yergeau, editors; "<cite>Extensible Markup Language (XML ) 1.0 (Third Edition)</cite>", W3C Recommendation, 4 February 2004
2949 <dd>(<a href="http://www.w3.org/TR/REC-xml/"><code>http://www.w3.org/TR/REC-xm l/</code></a>)
2950
2951 <dt>[XMLNAMES]
2952 <dd><a name="refsXMLNAMES"></a> Tim Bray, Dave Hollander, Andrew Layman, edito rs; "<cite>Namespaces in XML</cite>", W3C Recommendation, 14 January 1999
2953 <dd>(<a href="http://www.w3.org/TR/REC-xml-names/"><code>http://www.w3.org/TR/ REC-xml-names/</code></a>)
2954
2955 <dt>[YACC]
2956 <dd><a name="refsYACC"></a> S. C. Johnson; "<cite>YACC &mdash; Yet another com piler compiler</cite>", Technical Report, Murray Hill, 1975
2957
2958 </dl>
2959 </body>
2960 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698