Hi,
I would like to ask a question about selector's syntax. I have read a book and the syntax example is
div#example
{
....
}
I wonder if we can write in the following way or not.
div #example
{
....
}
There is a space between element and id selector. Also, I have the same question
p .warning
{
....
}
Thank in advance,
Duc
they have different
they have different meanings.
div#example refers to a div with an id of example while
div #example refers to any element with an id of example which is a descendant of a div
the same holds true for your other selector.
p .warning addresses an element with a class of warning which is a descendant of a p.
p.warning addresses a p with a class of warning
Thank you very much.
Thank you very much.
I have one more example. We
I have one more example. We set the declaration as follow,
div #example
{
color:red;
}
What color is the text?
You could probably work out
You could probably work out the answer to this from wolfies reply earlier, but it depends it could well be, and most probably would be the case that the text would be red, but the question is a false one as it is simply not possible to give an answer, what the color would be would entirely depend on the markup you had (likely the id would be a child of a div, if not then it would't apply), there is nothing wrong per se with what you have written.
It's always best to read through the specs to get the best and acurate detail on the subject and don't rely too much on a single book always google as much as possible as this way you will find many sites explaining the subject.
http://www.w3.org/TR/REC-CSS2/selector.html
Edit: Of course it would have helped if I had observed the markup example, but I think TPH (a.k.a 'Hot Stuff' or 'Lambykins' *sigh* ) has covered things pretty much, but have a read of the W3C link as well.
Hugo.
Without seeing the rest of
Without seeing the rest of the code, we can't say.
For example:
Hello world!
the text would inherit the body color
Hello world!
text would be red
Hello world!
text would also be red
Hello world!
text would NOT be red.
Thank you very much.
Thank you very much.
You're quite welcome
You're quite welcome