Skip to content

Commit fe326a1

Browse files
committed
Add the Selector Scoping section, explaining the difference between the two different types of selector scoping.
--HG-- extra : rebase_source : cd60b6ad69ead278b5ff7e6bd77dae3951390c58
1 parent 2c1fc04 commit fe326a1

2 files changed

Lines changed: 97 additions & 6 deletions

File tree

selectors4/Overview.html

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ <h2 class="no-num no-toc" id=contents>Table of Contents</h2>
183183

184184
<li><a href="#invalid"><span class=secno>3.8. </span> Invalid Selectors
185185
and Error Handling</a>
186+
187+
<li><a href="#selector-scoping"><span class=secno>3.9. </span> Selector
188+
Scoping</a>
186189
</ul>
187190

188191
<li><a href="#logical-combination"><span class=secno>4. </span> Logical
@@ -1367,6 +1370,50 @@ <h3 id=invalid><span class=secno>3.8. </span> Invalid Selectors and Error
13671370
that the last rule be dropped in favor of Media Queries-style
13681371
error-handling.
13691372

1373+
<h3 id=selector-scoping><span class=secno>3.9. </span> Selector Scoping</h3>
1374+
1375+
<p> In some instances, selectors may be "scoped", or limited in some way to
1376+
apply only within a section of the document.
1377+
1378+
<p> There are two distinct ways in which selectors can be scoped:
1379+
1380+
<dl>
1381+
<dt><dfn id=scope-contained0>scope-contained</dfn>
1382+
1383+
<dd> When a selector is <a
1384+
href="#scope-contained0"><i>scope-contained</i></a>, it matches as if the
1385+
elements outside of its scope did not exist. In other words, it acts like
1386+
the scope defines a sub-document within which the selector is matched.
1387+
1388+
<dt><dfn id=scope-limited>scope-limited</dfn>
1389+
1390+
<dd> When a selector is <a href="#scope-limited"><i>scope-limited</i></a>,
1391+
it only matches if the target is within the scope. The rest of the
1392+
document is still acknowledged and can match all but the last part of the
1393+
selector; only the target (the element matched by the last compound
1394+
selector in the selector) is required to be within the scope.
1395+
</dl>
1396+
1397+
<div class=example>
1398+
<p> The <code>document.querySelector()</code> function defined in <a
1399+
href="#SELECTORS-API2"
1400+
rel=biblioentry>[SELECTORS-API2]<!--{{SELECTORS-API2}}--></a> allows the
1401+
author to define a <a href="#scope-limited"><i>scope-limited</i></a>
1402+
selector.
1403+
1404+
<p> On the other hand, the <code>document.find()</code> function defined
1405+
in <a href="#SELECTORS-API2"
1406+
rel=biblioentry>[SELECTORS-API2]<!--{{SELECTORS-API2}}--></a> and the
1407+
selectors within a scoped stylesheet, defined in <a href="#HTML5"
1408+
rel=biblioentry>[HTML5]<!--{{HTML5}}--></a>, define <a
1409+
href="#scope-contained0"><i>scope-contained</i></a> selectors.
1410+
</div>
1411+
1412+
<p> Both kinds of scoping define a <a
1413+
href="#contextual-reference-element-set"><i>contextual reference element
1414+
set</i></a>, which can be matched with the <a
1415+
href="#scope"><code>:scope</code></a> pseudo-class selector.
1416+
13701417
<h2 id=logical-combination><span class=secno>4. </span> Logical
13711418
Combinations</h2>
13721419

@@ -1847,10 +1894,7 @@ <h3 id=attribute-case><span class=secno>6.3. </span> Case-sensitivity</h3>
18471894
has a value of <code>hsides</code>, whether that value is represented as
18481895
<code>hsides</code>, <code>HSIDES</code>, <code>hSides</code>, etc. even
18491896
in an XML environment where attribute values are case-sensitive.
1850-
1851-
<pre>
1852-
<!-- -->[frame=hsides i] { border-style: solid none; }
1853-
</pre>
1897+
f<!-- -->[frame=hsides i] { border-style: solid none; }
18541898
</div>
18551899
<!-- plinss notes we may eventually want to choose other normalizations
18561900
for attribute matching; but since there's no normalization scheme

selectors4/Overview.src.html

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,54 @@ <h3 id="invalid">
731731
<p class="issue">It's been <a href="http://lists.w3.org/Archives/Public/www-style/2010Nov/0203.html">requested</a>
732732
that the last rule be dropped in favor of Media Queries-style error-handling.</p>
733733

734+
735+
<h3 id='selector-scoping'>
736+
Selector Scoping</h3>
737+
738+
<p>
739+
In some instances,
740+
selectors may be "scoped",
741+
or limited in some way to apply only within a section of the document.
742+
743+
<p>
744+
There are two distinct ways in which selectors can be scoped:
745+
746+
<dl>
747+
<dt><dfn>scope-contained</dfn>
748+
<dd>
749+
When a selector is <i>scope-contained</i>,
750+
it matches as if the elements outside of its scope did not exist.
751+
In other words,
752+
it acts like the scope defines a sub-document within which the selector is matched.
753+
754+
<dt><dfn>scope-limited</dfn>
755+
<dd>
756+
When a selector is <i>scope-limited</i>,
757+
it only matches if the target is within the scope.
758+
The rest of the document is still acknowledged
759+
and can match all but the last part of the selector;
760+
only the target
761+
(the element matched by the last compound selector in the selector)
762+
is required to be within the scope.
763+
</dl>
764+
765+
<div class='example'>
766+
<p>
767+
The <code>document.querySelector()</code> function defined in [[SELECTORS-API2]]
768+
allows the author to define a <i>scope-limited</i> selector.
769+
770+
<p>
771+
On the other hand, the <code>document.find()</code> function defined in [[SELECTORS-API2]]
772+
and the selectors within a scoped stylesheet, defined in [[HTML5]],
773+
define <i>scope-contained</i> selectors.
774+
</div>
775+
776+
<p>
777+
Both kinds of scoping define a <i>contextual reference element set</i>,
778+
which can be matched with the <code>:scope</code> pseudo-class selector.
779+
780+
781+
734782
<h2 id="logical-combination">
735783
Logical Combinations</h2>
736784

@@ -1163,8 +1211,7 @@ <h3 id="attribute-case">
11631211
has a value of <code>hsides</code>, whether that value is represented
11641212
as <code>hsides</code>, <code>HSIDES</code>, <code>hSides</code>, etc.
11651213
even in an XML environment where attribute values are case-sensitive.
1166-
<pre>
1167-
<!-- -->[frame=hsides i] { border-style: solid none; }
1214+
f<!-- -->[frame=hsides i] { border-style: solid none; }
11681215
</pre>
11691216
</div>
11701217

0 commit comments

Comments
 (0)