Why does this CSS mean this?

P

P@tty Ayers

Let's see if we can shed some light on this:
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,
 
P

P@tty Ayers

I really think it's just a bad question. It looks like either could be
correct.

Not sure why you all are saying that. It reads to me 100% precise and clear,
and the answer correct. :) Sorry to disagree, but I see no ambiguity
whatsoever.
 
N

needin4mation

P@tty Ayers said:
Not sure why you all are saying that. It reads to me 100% precise and clear,
and the answer correct. :) Sorry to disagree, but I see no ambiguity
whatsoever.


--
Patty Ayers | www.WebDevBiz.com
Free Articles on the Business of Web Development
Web Design Contract, Estimate Request Form, Estimate Worksheet
--

If p had a class ,<p class=old> text <em> more text </em></p>, is <em>
part of the class .old or just part of p?

just for my memory:
"Select any <em> tag that's both part of the class old and within a <p>

tag."
 
P

P@tty Ayers

Wow, Murray. Ok, I'll take off the gloves. I don't like to embarass you, but
I'm afraid it's you who doesn't understand CSS. I'm surprised, because I
thought you did. The book the OP quoted was 100% correct. Feel free to take
this to any expert you like. I've explained it clearly several times.


--
Patty Ayers | www.WebDevBiz.com
Free Articles on the Business of Web Development
Web Design Contract, Estimate Request Form, Estimate Worksheet
--




Murray said:
You need glasses, and a better understanding of CSS, I'm afraid.
 
P

P@tty Ayers

I don't think it's appropriate to continue to debate this with you here,
Murray - plus, everything is very clear in the posts I've made already.


--
Patty Ayers | www.WebDevBiz.com
Free Articles on the Business of Web Development
Web Design Contract, Estimate Request Form, Estimate Worksheet
--



P@tty Ayers said:
Wow, Murray. Ok, I'll take off the gloves. I don't like to embarass you,
but I'm afraid it's you who doesn't understand CSS. I'm surprised, because
I thought you did. The book the OP quoted was 100% correct. Feel free to
take this to any expert you like. I've explained it clearly several times.
 
W

Windsun

Instead of getting personal about this, why not just make up a CSS style
sheet using both and see what does what.

-------------------------------------------------------------------------
P@tty Ayers said:
Wow, Murray. Ok, I'll take off the gloves. I don't like to embarass you,
but I'm afraid it's you who doesn't understand CSS. I'm surprised, because
I thought you did. The book the OP quoted was 100% correct. Feel free to
take this to any expert you like. I've explained it clearly several times.
 
M

Murray

Good idea. The class="old" styles will inherit into the <em> tag's
contents.

So - as stated at the beginning of the thread -

..old { font-weight:bold;color:red; }

<p class="old">This is <em>some text</em> in the middle of the line.</p>

What color is the text between <em> and </em>?
 
P

P@tty Ayers

Murray, I'm not (and haven't been) disputing that inheritance works that
way.

May I ask you two questions? If you could answer them directly, it might
shed some light on this. It could be an issue of semantics (English
semantics).

p em.old = "Select any <em> tag that's both part of the class old and
within a <p>
tag"

The above is true. So why do you agree with the OP that the book is
incorrect?

And why agree with the OP's suggestion that the selector "p.old em" is what
the translation for that text string *should* be, when "p.old em" means
something different, namely, "Select any <em> tag that's a descendant of a p
element with a class attribute of old" ?
 
M

Murray

The above is true. So why do you agree with the OP that the book is
incorrect?

Because the other instance is also true. It's an ambiguous question. Both
offered answers are true. There cannot be a binary choice between them.
 
P

P@tty Ayers

Murray said:
Because the other instance is also true. It's an ambiguous question.
Both offered answers are true. There cannot be a binary choice between
them.

Ok, so you are claiming that. At least I know what we disagree on.
 
M

Murray

I am trying to find a concensus on what "...part of the class old" means.

I believe that this is where we have our disagreement.

If I am incorrect in my interpretation, I'll post it here. I am really only
interested in finding out what is the correct answer, not in any contest....
 
P

P@tty Ayers

I am trying to find a concensus on what "...part of the class old" means.

I believe you're right that that is the source of the confusion. That phrase
doesn't *have* a clear meaning, and I don't see any point in trying to
assign it one by guessing at the author's intention. It could mean several
things, and each of them would be better off phrased in another way which
would make them completely clear.

The intended meaning appears to be one or the other of the following clear,
accepted expressions:

"with a class attribute of"

or

"which is a descendent of an element with a class attribute of",

....and it needs to be specified which one is meant.

I'm fairly sure that if this semantic wild-card phrase is removed from the
equation, you and I would have no disagreement.

:)
 
M

Murray

I'm fairly sure that if this semantic wild-card phrase is removed from the
equation, you and I would have no disagreement.

Yes, I'm completely confident of that. But perhaps that, too, is an
indication of the value of these <your favorite topic> in 24 hour books!
 
P

P@tty Ayers

Murray said:
Yes, I'm completely confident of that.

Semantics strikes again (English semantics, I mean!)
But perhaps that, too, is an indication of the value of these <your
favorite topic> in 24 hour books!

Good point.

<hugs and kisses> :-D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top