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
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.
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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now