tags:

views:

67

answers:

3

I'm using .class1.class2 .class3 selector, where .class1.class is a combination selector and .class3 belongs to a descendant. works fine in FF, but on IE7, it doesn't work. In the css below, the second style is always shown in IE. any solution?

 
<STYLE type="text/css">
.test1.test2 .test3{
    width:90px;
    height:100px;
}
.test4.test2 .test3{
    width:900px;
    height:100px;
}
</style>


<div class="test1 test2">
    <button value="test" class="test3"/>
</div>
A: 

Use Conditional Comments , this issue has been raised too many times here is an example :

<!--[if lte IE 9>
<style type="text/css">
.test1,.test2,.test3{
    width:90px;
    height:100px;
}
.test4,.test2,.test3{
    width:900px;
    height:100px;
}
</style>

<![endif]-->

This means all IE family browser less than version 9 are going to read in this style, or you can use style with # to be read by IE like this :

<STYLE type="text/css">
.test1,.test2,.test3{
    #width:90px;
    #height:100px;
}
.test4,.test2,.test3{
    #width:900px;
    #height:100px;
}
</style>
c0mrade
But why? I still don't understand why IE would get this wrong in the first place.
Pekka
But the example you provided is not a combination, I have .test1.test2 as a combination and .test3 belongs to a descendant.
A: 

That style should work perfectly on IE7+. As Pekka said in the comments there is a small problem with IE6. I'm guessing that you're not using the strict doctype perhaps?
In which case, you deserve everything you get :-o

Just add <!doctype html> to the start of the HTML file and everything should be fine.

DisgruntledGoat
seems like everyone except Nick misunderstood the question, the css in question is.test1.test2<SPACE>.test3
adding <!doctype html> works. But I'm already using IE7, not IE6
Sorry if I wasn't clear - the strict doctype is to make it work in IE7. Not sure what you mean in your first comment; I know what the CSS is. IE's problem is using two classes on one element i.e. the `.test1.test2` part
DisgruntledGoat
+3  A: 

just for let you know, what you are using is called Multiple Classes method! IE7 need to use this form:

div.class1.class2 div.class3 {}

IE6 don't suppurt this you can hack it, read the solution

http://www.quirksmode.org/css/multipleclasses.html

hope this help!

aSeptik