Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:28:49+00:00 2026-06-12T06:28:49+00:00

I have a structure: <div id=div> <ul class=ul> <li class=li_one> </li> <li class=li_two> </li>

  • 0

I have a structure:

<div id="div">
    <ul class="ul">
        <li class="li_one">
        </li>
        <li class="li_two">
        </li>
    </ul>
</div>

I want to set background:red to the second li element (class “li_two”) using pseudo-selectors and want to begin from the most outer div. I’m trying to this way:

#div > ul:nth-child(1) { background:red; }   // works but wrong, sets background to ul
#div ul:last-child { background:red; }   // doesn't set to any element
#div ul:first-child { background:red; }  // again sets to ul but not to li
#div [class=li_two] { background:red; }  // only this one works fine

Is it possible to set style to li_two from #div using :nth-child or :last-child or :first-child selectors? How to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:28:51+00:00Added an answer on June 12, 2026 at 6:28 am

    #div li:last-child

    Your 2nd option was almost right 🙂 I think you misunderstood what last-child does. xx:last-child It doesn’t select the last child element of element xx; it selects every xx element that is the last child of it’s parent.

    Some reading.

    I’ve created a JSFiddle for you to test it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jQuery(#element-id).parent().addClass('some-class'); I have a structure something like this: <div
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a
So, lets say that we have this structure: <div id='allTempLinkHolder'> <div class='tempLink'>Value</div> <div class='tempLink'>Value
I have this div structure <div class=panel> <div class=north></div> <div class=center></div> </div> The outer
I have below structure <div class=mybox> <div id=imageslide> <a href=><img src=url /></a> </div> </div>
I have a 9-box with a div structure like so: <div class=NBWrapper> <div class=NBTopRow>
I have a structure like: <div id=holder> <div id=first></div> <div class=box>I'm the first</div> <div
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
I have a simple HTML structure ( jsfiddle ): <li> <div class=buttons> <a href=done><img
If I have a structure like this: <div class=header> <div class=logo>[logo]</div> <div id=navigation class=cf>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.