cssquery-jquery.html 117 KB

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