P
P@tty Ayers
Let's see if we can shed some light on this:
I sure do, and that's exactly the same light I've been trying to shed on it
from the beginning. The book gave a text description of a selector:
"Select any <em> tag that's both part of the class old and within a <p>
tag."
....and provided the selector which does exactly that: "p em.old".
The book was correct and unambiguous. The original poster's understanding
wasn't correct though. He thought that the selector "p.old em" would mean
the same thing, which of course it doesn't. It should be translated,
"Select any em element that is a descendant of a p element with a class
attribute that contains the word old."
If the question were about the best way to write code to style that <em>
element, it would make sense to discuss which selector is more useful. But
the question was, what selector will do what was described, and the selector
the book provided was 100% accurate and unambiguous.
Whether a certain notation should be avoided or not might be an interesting
question; I've just been addressing the actual question the OP asked - what
selector does exactly what is described, and the book's answer was right.
Cheers,
Test case:
<p>Some <em class="old">text</em></p>
The above will be caught by the first style as there is an em tag with
the class old within a p tag. It will however not be caught by the
second style as p doesn't have a class called old.
You can describe the second style as such:
"Select any em tag that is within a p tag that has the class old".
See the difference?
I sure do, and that's exactly the same light I've been trying to shed on it
from the beginning. The book gave a text description of a selector:
"Select any <em> tag that's both part of the class old and within a <p>
tag."
....and provided the selector which does exactly that: "p em.old".
The book was correct and unambiguous. The original poster's understanding
wasn't correct though. He thought that the selector "p.old em" would mean
the same thing, which of course it doesn't. It should be translated,
"Select any em element that is a descendant of a p element with a class
attribute that contains the word old."
If the question were about the best way to write code to style that <em>
element, it would make sense to discuss which selector is more useful. But
the question was, what selector will do what was described, and the selector
the book provided was 100% accurate and unambiguous.
In my opinion this notation should be avoided as it is easy to lose
sight of just what is covered by it.
Whether a certain notation should be avoided or not might be an interesting
question; I've just been addressing the actual question the OP asked - what
selector does exactly what is described, and the book's answer was right.
Cheers,