Welcome to WebmasterWorld Guest from 34.225.194.144
Forum Moderators: not2easy
Notice how the border color does not cascade. It remains at the default black color. If you remove the div#message.info{} declaration, then the border color cascades down and becomes red. So it's as if the .info one is blocking the .error one somehow.
CSS:
div#message {
border-width: 5px;
border-style: solid;
}
div#message.info {
border-color: green;
}
div#message.error {
border-color: red;
}
HTML 4.01:
<div id="message" class="error">An error message</div>
It's a "simple" selector without a combinator
I've found a given example in conjuction with using multiple class selectors [w3.org]
p.marine.pastoral { color: green }
IMHO, it all hinges on the word combinators, with CSS there are various ways to combine selectors and these are described in the Selector Syntax [w3.org] part of the spec.. however as usual when forced to read and interpret a recommendation it's nae easy ;)
A selector is a chain of one or more simple selectors separated by combinators. Combinators are: whitespace, ">", and "+". Whitespace may appear between a combinator and the simple selectors around it.The elements of the document tree that match a selector are called subjects of the selector. A selector consisting of a single simple selector matches any element satisfying its requirements. Prepending a simple selector and combinator to a chain imposes additional matching constraints, so the subjects of a selector are always a subset of the elements matching the last simple selector.
So my reading of that is that a selector can be a chain, separated by one of 3 different combinators; the example given by moltar and the CSS2.1 multiple class example does not need or use a combinator, there is no whitespace, or indeed anything else (in fact if there were whitespace between the simple selectors it would alter the target) - so to my interpretation this is a really really simple selector which simply says the selector has to match all.
I do have some vague recollection of reading something previously about IE and this type of selector, where it only matched the last selector in a chain, but I've ran some tests and all seems OK so perhaps (even if a problem did exist briefly) it was fixed between IE7beta and release, and back testing seems to back up moltars claim, in that it always was OK!
anyway no matter, moltar the code you gave is working fine for me, as in I am not seeing the default color and I am seeing the green or red border depending on which class I put in the HTML, what's the doctype and context and sorry for being cheeky but is the speeling and case correct?
[edited by: SuzyUK at 6:03 pm (utc) on Feb. 3, 2008]