Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

elements with multiple css classes 1

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo I have some elements with more then one classes, something like this:

Code:
<ul>
  <li class="SelectedTab Level2"><a href="">test</a></li>
  <li class="SelectedTab Level3"><a href="">test</a></li>
  <li class="Level3"><a href="">test</a></li>
  <li class="Level2"><a href="" >test</a></li>
</ul>

With this class structure, is it possible to reach every single element and style it differently then the others?
(ex. first = blue, second = red, third = green, forth = yellow)

Thanks
 
the siblings technique wouldn't work because I actually don't know the exact order of the LI tags, the one I posted is an example. It could be:

Code:
<ul>
  <li class="Level2"><a href="" >test</a></li>
  <li class="Level3"><a href="">test</a></li>
  <li class="SelectedTab Level2"><a href="">test</a></li>
  <li class="SelectedTab Level3"><a href="">test</a></li>
</ul>
 
I would like to be able to say something like:

if Level 2 = color1
if Level 3 = color2
if Level 2 AND SelectedTab = color3
if Level 3 AND SelectedTab = color4

The color should depend on the classes.

 
Then how about using the styles:

Code:
.Level2{
color:#FFFFFF;

}

.Level3{
color:#0000FF;
}


.SelectedTab.Level3{
color:#FF0000;
}

.SelectedTab.Level2{
color:#00FF00;
}

This will make an object with a class of level2 have a white color, however an object with classes SelectedTab and Level2 will have a Green Color instead.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Please note that although that is the correct way to do it, it won't work correctly in IE6, because that browser poorly implements the two classes selector (it assumes OR instead of AND). So, if you will need to support IE6, you will need to think of something else.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top