On Sun, 25 Feb 2007, forget color wrote:

I'm having trouble setting attributes globally for a parent block and
then turning them off for selected child blocks.

You cannot actually turn them off, just to set them to other values. The point here is that you cannot tell the browser to use its default values for, say, some property of some <ul> element once you have set the property for <ul> elements in general.

But it seems that here it is sufficient to set the property to a specific value. This requires some care due to the somewhat unintuitive features of the cascade.

#block li {
 color:red;
}

.childblock ul li  {
 color:blue;
}

As Björn wrote in his reply, the latter rule would refer to <li> elements inside a <ul> element that is inside an element in class "childblock", and you have no such elements.

However, although
ul.childblock li { ... }
would refer to the elements to which you wish it to apply, it won't take effect. The cascade rules imply that the color is still red, since the first rule has a selector with higher specificity (#block li). By the specificity rules, a selector containing an identifier selector (with "#") takes precedence over a selector without such a selector.

The point is that #block li refers to _all_ li elements inside an element with id="block", and this cannot be overridden for some of such elements just by writing a later rule that applies to them. The order of CSS rules is relevant in the cascade in special cases only - when specificities are equal. This might be seen as counter-intuitive, but we have to live with it.

Thus, a simple fix is to have
#block .childblock li { color: blue; }

You could alternatively have
#block ul.childblock li { color: blue; }
but the version without the element name is more flexible, since it covers both <ul class="childblock">...</ul> and <div class="childblock"><ul>...</ul></div>.

(You should always set background when you set color, but I won't go into that somewhat hot topic here, beyond just mentioning the issue.)

--
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
IE7 information -- http://css-discuss.incutio.com/?page=IE7
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to