Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use double classes in IE6 CSS?

Tags:

is there any way to make IE6 understand double classes, say I have a class MenuButton with a color class and possibly a clicked class; like :

.LeftContent a.MenuButton {..general rules..}   .LeftContent a.MenuButton.Orange {..sets background-image..}   .LeftContent a.MenuButton.Clicked {...hum ta dum...} 

Now, IE6 understands <a class="MenuButton Orange">, but when adding Clicked, like <a class="MenuButton Orange Clicked">, IE just ignores the Clicked rule.

Of course, I could rewrite my CSS, and have own rules for .MenuButtonOrange
and such (and it'd probably taken a lot shorter time than asking this question ;-),
but golly, it just so unappealing and Web 0.9...

Cheers!

like image 555
Morten Bergfall Avatar asked Nov 23 '08 02:11

Morten Bergfall


People also ask

Can CSS have two classes?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.

Can we use ID and class together in CSS?

Yes you can. You just need to understand what they are for, the class is more general and can be used several times, the id (is like your id's) you can use it only once.


2 Answers

IE6 doesn't support multiple class selectors. The reason you see a change with the Orange class is because a.MenuButton.Orange is interpreted by IE6 as a.Orange.

I recommend structuring your markup in such a way that you can work around this:

<div class="leftcontent">    <ul class="navmenu">      <li><a class="menubutton orange" href="#">One</a></li>      <li><a class="menubutton orange clicked" href="#">Two</a></li>    </ul> </div> 

By grouping by a more specific ancestor you can create variation with classes scoped by that ancestor (in this example navmenu):

.leftcontent .navmenu a { /* ... basic styles ... */ } .leftcontent .navmenu a.orange { /* ... extra orange ... */ } .leftcontent .navmenu a.clicked { /* ... bold text ... */ } 

It's not as good as multiple classes, but I've used it to work around the lack of support in IE.

like image 105
Borgar Avatar answered Nov 26 '22 07:11

Borgar


Dean Edwards' IE7 script adds multiple class support for IE6. See http://code.google.com/p/ie7-js/

like image 22
Squig Avatar answered Nov 26 '22 07:11

Squig