@@ -657,11 +657,11 @@ Data Model</h3>
657657 but not only elements with <a>shadow trees</a> have ''::shadow'' pseudo-elements.
658658 </div>
659659
660- Four aspects of a DOM element are especially relevant for selectors:
660+ Five aspects of a DOM element are especially relevant for selectors:
661661
662662 <ul>
663- <li> The element's type (also known as tagname),
664- which is a pair of strings: a namespace and a local name .
663+ <li> The element's type (also known as tagname), which is a string.
664+ <li> The element's namespace, which is a string .
665665 <li> An ID, which is a string.
666666 <li> Classes, which are strings.
667667 <li> Attributes, which are pairs of strings consisting of an attribute name and an attribute value.
@@ -673,12 +673,12 @@ Data Model</h3>
673673 are called <dfn export title="feature selector">feature selectors</dfn> .
674674
675675 While elements may lack any of the individual <a>features</a> ,
676- some elements are <dfn export>featureless</dfn> ,
677- which means that not only do they lack any <a>features </a>
678- (and thus will never match a <a>feature selector </a> ),
679- but any selectors that reference <a>features</a> ,
680- such as '':not(div)'' ,
681- also never match them .
676+ some elements are <dfn export>featureless</dfn> .
677+ A <a>featureless</a> element does not match any <a>feature selector </a> ,
678+ or any selector that resolves based on <a>features </a>
679+ (such as '':not(div)'' ) ,
680+ with the exception of namespace selectors--
681+ a <a>featureless</a> element is treated as having <em> all </em> namespaces .
682682 Thus, only <a>pseudo-classes</a> or <a>pseudo-elements</a> can be used to select them.
683683 Individual <a>featureless</a> elements may define additional restrictions on what kinds of selectors can match them.
684684
@@ -687,6 +687,25 @@ Data Model</h3>
687687 and can't be matched by <em> any</em> <a>pseudo-class</a> except for '':host'' and '':host-context()'' .)
688688 </div>
689689
690+ <details class='why'>
691+ <summary> Why do featureless elements match all namespaces?</summary>
692+
693+ In a previous version of Selectors,
694+ all <a>compound selectors</a> contained a <a>type selector</a> ;
695+ if you didn't supply one explicitly,
696+ a <a>universal selector</a> was implied.
697+ Default namespaces [[CSS3NAMESPACE]] affected the implied universal selector,
698+ so that selectors like '':hover'' actually meant ''defaultNS|*:hover'' .
699+
700+ The universal selector is no longer implied,
701+ but default namespaces still exist,
702+ and have to apply to all compound selectors.
703+ The behavior of <a>featureless</a> elements,
704+ like the <a>host element</a> in a shadow tree,
705+ thus needs to accommodate that and work appropriately.
706+ In this case, "appropriately" means "ignoring the default namespace".
707+ </details>
708+
690709 When matching a selector against a document which is in <a>quirks mode</a> ,
691710 class and ID selectors must be matched <a title="ASCII case-insensitive">ASCII case-insensitively</a>
692711 against the classes and ID of the elements in the document.
@@ -724,9 +743,9 @@ Guidance on Mapping Document Languages to DOM</h4>
724743
725744 If this "type" can be separated into a "basic" name
726745 and a "namespace" that groups names into higher-level groups,
727- that should be reflected in the "namespace" and "local name" divisions of the "type " <a>feature</a> .
728- Otherwise, the "namespace" part should be the empty string ,
729- and the entire name should be in the "local name" part .
746+ the latter should be reflected as the "namespace" <a>feature</a> .
747+ Otherwise, the element shouldn't have a "namespace" <a>feature</a> ,
748+ and the entire name should be reflected as the "type" <a>feature</a> .
730749
731750 <dt> id
732751 <dd>
@@ -1203,8 +1222,11 @@ The Matches-Any Pseudo-class: '':matches()''</h3>
12031222 Pseudo-elements cannot be represented by the matches-any pseudo-class;
12041223 they are not valid within '':matches()'' .
12051224
1206- Default namespace declarations do not affect any “implied” universal selectors
1207- within a '':matches()'' pseudo-class.
1225+ Within a '':matches()'' pseudo-class,
1226+ default namespace declarations only have an effect on compound selectors
1227+ that contain a <a>type selector</a> .
1228+
1229+ Issue: Do we want to extend this protection from default namespaces to other things?
12081230
12091231 <div class="example">
12101232 For example, the following selector matches any element that is being
@@ -1301,51 +1323,62 @@ Elemental selectors</h2>
13011323Type (tag name) selector</h3>
13021324
13031325 A <dfn export>type selector</dfn> is the name of a document language element type
1304- written using the syntax of <a href="http://www.w3.org/TR/css3-namespace/#css-qnames">CSS qualified names</a> [[!CSS3NAMESPACE]] .
1326+ written as either an <a>identifier</a>
1327+ or, if interacting with namespaces,
1328+ a <a>CSS qualified name</a>
1329+ (see [[#type-nmsp]] )
1330+ [[!CSS3NAMESPACE]] .
1331+
13051332 A type selector represents an instance of the element type in the document tree.
13061333
13071334 <div class="example">
1308- Example:
1309- The following selector represents an <a element>h1</a> element in the document tree:
1310-
1311- <pre> h1 </pre>
1335+ For example, the selector ''h1'' represents an <a element>h1</a> element in the document.
13121336 </div>
13131337
1314- <h4 id="typenmsp ">
1315- Type selectors and namespaces</h4 >
1338+ <h3 id="the-universal-selector ">
1339+ Universal selector </h3 >
13161340
1317- Type selectors allow an optional namespace component: a namespace
1318- prefix that has been previously <a href="#nsdecl">declared</a> may be
1319- prepended to the element name separated by the namespace separator
1320- "vertical bar" (U+007C, <code> | </code> ). (See, e.g., [[XML-NAMES]] for the use of namespaces in
1321- XML.)
1341+ The <dfn export>universal selector</dfn> is a special <a>type selector</a> ,
1342+ written either as the asterisk character ( <code> * </code> U+002A),
1343+ or as a <a>CSS qualified name</a>
1344+ with an asterisk as the local name (see [[#type-nmsp]] ).
1345+ It represents an element with any name.
13221346
1323- The namespace component may be left empty (no prefix before the
1324- namespace separator) to indicate that the selector is only to
1325- represent elements with no namespace.
1347+ Like a <a>type selector</a> ,
1348+ the <a>universal selector</a> can be qualified by a namespace,
1349+ and is affected by a default namespace as defined in [[#type-nmsp]] .
13261350
1327- An asterisk may be used for the namespace prefix, indicating that
1328- the selector represents elements in any namespace (including elements
1329- with no namespace).
1351+ Unless an element is <a>featureless</a> ,
1352+ the presence of a <a>universal selector</a> has no effect on whether the element matches the selector.
1353+ (<a>Featureless</a> elements do not match any <a>feature</a> selector,
1354+ including the <a>universal selector</a> .)
13301355
1331- Element type selectors that have no namespace component (no
1332- namespace separator) represent elements without regard to the
1333- element's namespace (equivalent to "<code> *|</code> ") unless a default
1334- namespace has been <a href="#nsdecl">declared</a> for namespaced selectors (e.g. in CSS, in
1335- the style sheet). If a default namespace has been declared, such
1336- selectors will represent only elements in the default namespace.
1356+ <div class="example">
1357+ <ul>
1358+ <li>
1359+ <span class=css> *[hreflang|=en] </span> and <span class=css> [hreflang|=en] </span> are equivalent,
1360+ <li> ''*.warning'' and ''.warning'' are equivalent,
1361+ <li> ''*#myid'' and ''#myid'' are equivalent.
1362+ </ul>
1363+ </div>
13371364
1338- A type selector containing a namespace prefix that has not been
1339- previously <a href="#nsdecl">declared </a> for namespaced selectors is
1340- an <a href="#conformance">invalid </a> selector.
1365+ The <a>universal selector</a> follows the same syntax rules as other <a>type selectors</a> :
1366+ only one can appear per <a>compound selector </a>,
1367+ and it must be the first <a>simple selector </a> in the <a>compound selector</a> .
13411368
1342- In a namespace-aware client,
1343- the name part of element type selectors
1344- (the part after the namespace separator, if it is present)
1345- will only match against the <a href="http://www.w3.org/TR/REC-xml-names/#NT-LocalPart">local part</a>
1346- of the element's <a href="http://www.w3.org/TR/REC-xml-names/#ns-qualnames">qualified name</a> .
1369+ Note: In some cases, adding a <a>universal selector</a> can make a selector easier to read,
1370+ even though it has no effect on the matching behavior.
1371+ For example, ''div :first-child'' and ''div:first-child'' are somewhat difficult to tell apart at a quick glance,
1372+ but writing the former as ''div *:first-child'' makes the difference obvious.
13471373
1348- In summary:
1374+ <h3 id='type-nmsp'>
1375+ Namespaces in Selectors</h3>
1376+
1377+ <a>Type selectors</a> allow an optional namespace component:
1378+ a namespace prefix that has been previously <a href="#nsdecl">declared</a>
1379+ may be prepended to the element name separated by the namespace separator “vertical bar” (<code> |</code> U+007C).
1380+ (See, e.g., [[XML-NAMES]] for the use of namespaces in XML.)
1381+ It has the following meaning in each form:
13491382
13501383 <dl>
13511384 <dt><code> ns|E</code>
@@ -1398,70 +1431,23 @@ Type selectors and namespaces</h4>
13981431 namespace has been defined.
13991432 </div>
14001433
1401- <h3 id="the-universal-selector">
1402- Universal selector </h3>
1403-
1404- The <dfn export>universal selector</dfn> , written as a
1405- <a href="http://www.w3.org/TR/css3-namespace/#css-qnames">CSS qualified
1406- name</a> [[!CSS3NAMESPACE]] with an asterisk (<code> *</code>
1407- U+002A) as the local name, represents the qualified name of any element
1408- type. It represents any single element in the document tree in any
1409- namespace (including those without a namespace) if no default
1410- namespace has been specified for selectors. If a default namespace has
1411- been specified, see <a href="#univnmsp">Universal selector and
1412- Namespaces</a> below.
1413-
1414- If a universal selector represented by ''*''
1415- (i.e. without a namespace prefix)
1416- is not the only component of a <a>compound selector</a>
1417- or is immediately followed by a <a>pseudo-element</a> ,
1418- then the ''*'' may be omitted
1419- and the universal selector's presence implied.
1420-
1421- <div class="example">
1422- <ul>
1423- <li> ''*[hreflang|=en]'' and ''[hreflang|=en]'' are equivalent,
1424- <li> ''*.warning'' and ''.warning'' are equivalent,
1425- <li> ''*#myid'' and ''#myid'' are equivalent.
1426- </ul>
1427- </div>
1428-
1429- Note: It is recommended that the ''*'' not be omitted,
1430- because it decreases the potential confusion between,
1431- for example, ''div :first-child''
1432- and ''div:first-child'' .
1433- Here, ''div *:first-child'' is more readable.
1434-
1435- <h4 id="univnmsp">
1436- Universal selector and namespaces</h4>
1437-
1438- The universal selector allows an optional namespace component. It
1439- is used as follows:
1440-
1441- <dl>
1442- <dt> ''ns|*''
1443- <dd>
1444- all elements in namespace ns
1434+ If a <a>default namespace</a> is declared,
1435+ <a>compound selectors</a> without <a>type selectors</a> in them
1436+ still only match elements in that default namespace.
14451437
1446- <dt> ''*|*''
1447- <dd>
1448- all elements
1438+ <div class='example'>
1439+ For example,
1440+ in the following stylesheet:
14491441
1450- <dt> ''|*''
1451- <dd>
1452- all elements without a namespace
1442+ <pre>
1443+ @namespace url("http://example.com/foo");
14531444
1454- <dt> ''*''
1455- <dd>
1456- if no default namespace has been specified,
1457- this is equivalent to *|*.
1458- Otherwise it is equivalent to ns|*
1459- where ns is the default namespace.
1460- </dl>
1445+ .special { ... }
1446+ </pre>
14611447
1462- A universal selector containing a namespace prefix
1463- that has not been previously <a href="#nsdecl">declared</a>
1464- is an <a>invalid selector</a> .
1448+ The ''.special'' selector only matches elements in the "http://example.com/foo" namespace,
1449+ even though no reference to the type name (which is paired with the namespace in the DOM) appeared.
1450+ </div>
14651451
14661452
14671453<h2 id="attribute-selectors">
0 commit comments