Jump to content

first-child problems


tinman

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...