Forum Moderators: not2easy

Message Too Old, No Replies

selector for multiple classes?

         

narowgate

1:42 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



You can define multiple classes to a single element, but can I define a style only when multiple classes are present?

So can I have one style for A, one style for B, and yet another style only when the class is A AND B?

createErrorMsg

2:48 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So can I have one style for A, one style for B, and yet another style only when the class is A AND B?

In theory, you absolutely can do this. Here's a small test page with the proper syntax...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style>
.a.b{
color:orange;
}
</style>
</head>
<body>
<p class="a b">Lorem ipsum dolro sit amet.</p>
<p class="a">Lorem ipsum dolro sit amet.</p>
<p class="b">Lorem ipsum dolro sit amet.</p>
</body>
</html>

The above CSS indicates that an element with both class names have orange text, and would apply to the first paragraph, but not the second or third. Try it in Firefox and you'll see that it works, EXCEPT...

Now try it in IE. Doesn't work. IE has a bug where it will take the styles in that multi-class selector and apply them to elements with BOTH classes (like FF) AND elements with just the second class (not like FF). This means that in IE, the text for the first and the third paragraphs is orange, not just the first.

Sadly, there is not any way around this at the moment, short of using multiple classes in a way that allows you to combine single classes in the html, but not the css, to get your desired effect.

cEM