tinman Posted January 30, 2012 Report Posted January 30, 2012 I am creating a dropdown for a site, but cant seem to get it so only a few of the list items are effected by a certain effect. Here is a much shorter example of what my coding will look like. <html> <head> <style type="text/css"> li:first-child { background:yellow; } </style> </head> <body> <ul> <li><a href="#">Coffee</a> <ul> <li><a href="#">fdas</a></li> <li><a href="#">fdas</a></li> </ul> </li> <li><a href="#">Tea</a></li> <li><a href="#">Coca Cola</a></li> </ul> </body> </html> I am trying to make it so only Coffee, Tea, and Coca Cola are highlighted. while fdas isn't. Thank you for your time and consideration Quote
Symphlion Posted January 30, 2012 Report Posted January 30, 2012 Use classes. Using the first-child attribute is going to affect all first-child elements it can find. Either that or you should use it on the ul:first-child. That way, you only target the first li elements. However, this way, Coca Cola will not be highlighted since Coca Cola is not the first child of ul. Quote
tinman Posted January 31, 2012 Author Report Posted January 31, 2012 Classes worked. Thank you. For some reason I had it in my mind that I couldn't use classes because it was a hover pseudo-class. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.