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

  • SEARCH
  • Home
  • 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 9167959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:02+00:00 2026-06-17T15:31:02+00:00

I have a simple menu with two buttons and each button is a dropdown;

  • 0

I have a simple menu with two buttons and each button is a dropdown; each display two sub-buttons. I want for each sub item to be a different background color, as you can see from my CSS below.

#nav:first-child > li li:first-child {background: yellow;}
#nav:first-child > li li:nth-child(2) {background: red;}
#nav:nth-child(2) > li li:first-child {background: green;}
#nav:nth-child(2) > li li:nth-child(2) {background: blue;}

So far my CSS only works for the first sub-buttons; sub-button one is yellow, and sub-button two is red. Unfortunately sub-button three is yellow instead of green, and sub-button four is red instead of blue. How can I change my last two lines of code to achieve the desired results?

**keep in mind, the dropdown is a nested LIST. HTML example below:

<div id="nav">
   <ul>
      <li>link 1
          <ul>
             <li>SUB link 1</li>
             <li>SUB link 2</li>
         </ul>
      </li>
      <li>link 2
         <ul>
             <li>SUB link 3</li>
             <li>SUB link 4</li>
         </ul>
      </li>
   </ul>
</div>
  • 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-17T15:31:03+00:00Added an answer on June 17, 2026 at 3:31 pm

    IE7-8 Support

    You were using :nth-child to begin with, which is not supported in those browsers, so I can see why those who answered did not care about support, as it would have appeared that you did not care about such support. However, selectors can be made to work for those. Using the adjacent sibling combinator + with the :first-child in key points creates the same effect as :nth-child(2)

    See Fiddle.

    ul li:first-child > ul li:first-child {background: yellow;}
    ul li:first-child > ul li + li {background: red;}
    ul li:first-child + li > ul li:first-child {background: green;}
    ul li:first-child + li > ul li + li {background: blue;}
    

    IE6

    You cannot get IE6 support without either javascript or directly putting classes on each of the li elements, as IE6 does not support :first-child or +. Personally, for color variations, you should just let IE6 go. If you insist, and do not want to use javascript to get selector function through that, then you are resolved to change the html:

    <div id="nav">
       <ul>
          <li>link 1
              <ul>
                 <li class="one">SUB link 1</li>
                 <li class="two">SUB link 2</li>
             </ul>
          </li>
          <li>link 2
             <ul>
                 <li class="three">SUB link 3</li>
                 <li class="four">SUB link 4</li>
             </ul>
          </li>
       </ul>
    </div>
    

    With this

    .one {background: yellow;}
    .two {background: red;}
    .three {background: green;}
    .four {background: blue;}
    

    Of course, that would work on any browser supporting css. But that is also not what I suspect you want to do. So again, leave IE6 to itself and forget about accommodating the color change on that or use javascript (perhaps through Modernizr, Jquery, MooTools, etc.) to do it.

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

Sidebar

Related Questions

What I have here real simple activity with two buttons. When you press each
I have a simple dropdown menu: <form class=feedmenu align=center> <select onchange=showRSS1(this.value)> <option value=>Select an
I have a simple dropdown menu and I'd like to have this menu close/hide
I have a simple unordered list with list items as menu item i created
I have some simple markup: <table> <tr> <td>Menu Item</td> </tr> </table> <div> <table> <tr>
I have a simple two divs: <div id=slide_menu> <div id=tic>MENU</div> </div> And I would
I have a simple problem using Jquery. I want to display detailed information under
I have a simple program with one TextView and two Buttons: Button1 and Button2.
i have two questions Apple says there should not be any button or menu
I have a simple horizontal nav menu that uses highly-styled anchors for buttons. Now,

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.