Hi again!
CSS considers only element nodes to be children or siblings. The DOM
does not.
This is a pedagogic discrepancy understandable to people used in
traversing the DOM who are frustrated that MSIE is "natural" with
nextSibling and that the rest are according to spec.[1] Something that
has led to the Element Traversal Specification[2] and a lot of userland
convenience functions[3].
As for the DOM the spec actually makes sense, even if whitespace-only
text nodes can be ignored 99% of the time. Compare the following:
<li>
<a href="foo">bar</a>
</li>
with:
<p>
<em>I</em> <strong>really</strong> mean it.
</p>
In the first case the whitespace nodes are clearly without any real
value. In the second case that is true for the first whitespace only
text-node, between <p> and <em>, bit the second whitespace only text
node is useful, because it separates the word "I" from the word "really".
In CSS 3 there will be new selectors, and I wonder if it would not be
useful to clearly specify when whitespace is indeed ignorable and when
it is of real use. Consider the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test CSS 3 only-child selector</title>
<style type="text/css">
li > a {
background: lightblue;
}
li > a:only-child {
background: pink;
}
</style>
</head>
<body>
<h1>Test CSS 3 only-child selector</h1>
<ul>
<li><a href="">True only child XML-wise</a></li>
<li>
<a href="">Not only child XML-wise (whitespace)</a>
</li>
<li>Dummy text
<a href="">Clearly not only child XML-wise (textnode as
sibling)</a>
</li>
<li><span>Dummy text in span</span>
<a href="">Clearly not only child XML-wise</a>
</li>
</ul>
</body>
</html>
When I run this in FFox 2.0 I get three pink background a-elements and
the forth is light blue. One could reasonably argue that it should be
the other way around. But it is according to the spec[4]:
The only-child pseudoclass "Represents an element that has a parent
element and whose parent element has no other *element* children. Same
as :first-child:last-child or :nth-child(1):nth-last-child(1), but with
a lower specificity." (emphasis added)
Ergo: The second and third a-elements are not an only child from the DOM
point of view, but they are from an CSS POV.
Now to the question... Ooops! I actually forgot what I had intended to
ask. Well, enjoy my little CSS 3 test if nothing else...
Lars Gunther
1.
http://easy-designs.stikipad.com/IE-next-Wishlist/show/Don%27t+ignore+whitespace
2.
http://dev.w3.org/cvsweb/2006/webapi/ElementTraversal/publish/ElementTraversal.html?rev=1.4
3. Example from w3schools (there are better ones):
//check if the next sibling node is an element node
function get_nextsibling(n)
{
var x=n.nextSibling;
while (x.nodeType!=1)
{
x=x.nextSibling;
}
return x;
}
4. http://www.w3.org/TR/css3-selectors/#only-child-pseudo
*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************