Jump to content

Recommended Posts

Posted

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

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...