Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Targeting a specific element in html

<section>

    <nav class="navLinks">
        <li> <a href= "home.html" class= "selected">|Home|  </a> </li> 
        <li><a href= "about.html" > |About| </a> </li>
        <li><a href= "services.html"> |Services| </a> </li> 
        <li><a href= "location.html"> |Location| </a> </li> 
        <li><a href= "contact.html"> |Contact| </a> </li> 
    </nav>

</section>

This is the portion of code i have from my html file. I'm wanting target the fourth element, "location.html"; however, not sure how to do so. I think i have to use nth-child, but don't know how to implement it. Help please!!!! :)

.navLinks:nth-child(4n) {

}

i think that should work

1 Answer

You can also add a class or id to the item you wish to target.

Example:

    <nav class="navLinks">
        <li> <a href="home.html" class="selected">|Home|  </a> </li> 
        <li><a href="about.html" > |About| </a> </li>
        <li><a href="services.html"> |Services| </a> </li> 
        <li class="location"><a href="location.html"> |Location| </a> </li> 
        <li><a href="contact.html"> |Contact| </a> </li> 
    </nav>

</section>
.location {
/* Add CSS styling here*/
}