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 8758729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:37:19+00:00 2026-06-13T14:37:19+00:00

I have a navigation menu which has default styling… <nav> <ul id=MenuBar1 class=MenuBarHorizontal> <li>

  • 0

I have a navigation menu which has default styling…

<nav>   
 <ul id="MenuBar1" class="MenuBarHorizontal">
  <li>
   <a href="#">Home</a>
  </li>
  <li>
   <a class="MenuBarItemSubmenu" href="membership.php">Membership</a>
   <ul>
    <li><a href="#">General</a></li>
    <li>
     <a class="MenuBarItemSubmenu" href="#">Adult</a>
     <ul>
      <li><a href="#">Beginner</a></li>
      <li><a href="#">Intermediate</a></li>
      <li><a href="#">Advanced</a></li>
     </ul>                    
    </li>
   [...]
</nav>

There is styling for this like blah:

/* Menu items are a light gray block with padding and no text decoration */
ul.MenuBarHorizontal a {
 display: block;
 cursor: pointer;
 background-color: #000;
 padding: 0.5em 0.75em;
 color: #FFF;
 text-decoration: none;
}
/* Menu items that have mouse over or focus have an off-white background and dark text */
ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus {
 background-color: #EEE;
 color: #333;
}
/* Menu items that are open with submenus are set to MenuBarItemHover with an off-white background and dark text */
ul.MenuBarHorizontal a.MenuBarItemHover, ul.MenuBarHorizontal a.MenuBarItemSubmenuHover, ul.MenuBarHorizontal a.MenuBarSubmenuVisible {
 background-color: #EEE;
 color: #333;
} /* And so on... */

But I want something different for submenus, and also for items that are highlighted. This question isn’t specifically about that, because I have a solution which, if not the most elegant, makes sense, that is to construct an entirely different selector:

#topitem:hover, #topitem:focus {
 background-color: #FFF;
 color: #000;
}

#subitem:hover, #subitem:focus{
 background-color: #FFF;
 color: #000;
}

and then have the corresponding HTML

<nav>   
 <ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a href="#" id="topitem">Home</a></li>
  <li><a class="MenuBarItemSubmenu" id="topitem" href="membership.php">Membership</a>
 <ul> ...

This works fine.. but er… there shouldn’t be more than one instance of any id. So I say, K, let’s have these as classes:

CSS

.topitem:hover, .topitem:focus {
 background-color: #FFF;
 color: #000;
}

.subitem:hover, .subitem:focus {
 background-color: #FFF;
 color: #000;
}

HTML

 <nav>  
  <ul id="MenuBar1" class="MenuBarHorizontal">
   <li><a href="#" class="topitem">Home</a></li>
   <li><a class="MenuBarItemSubmenu topitem" href="membership.php">Membership</a>
    <ul> ... 

but much to my surprise this doesn’t work at all…

Anybody have any ideas?

  • 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-13T14:37:20+00:00Added an answer on June 13, 2026 at 2:37 pm

    The ID’ed version worked because CSS rules for IDs will always win out over those for classes.

    Class styling is then also dependant on when in the style sheet the rule is declared.

    If you declare your subitem style before you declare your default <li> style, then the default style will win out. Move the required style rules below the default style and that should solve your problem.

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

Sidebar

Related Questions

I have a menu set up this way: <div id='top-navigation'> <ul> <li><a class='top-nav-button-unclicked' href='#'>SUBJECT</a></li>
I have a navigation menu within a page on my site, which has JavaScript
I have an application that has a top level navigation menu which consists of
I have a separate navigation php which has a list of links and menu
I have two activities with navigation menu which has items for launching Activity1 and
I have my navigation menu in application.html and the menu has class=active . That
I have a drop down menu which has the following html structure: <ul class=menu>
I have a custom navigation menu for my SharePoint intranet web application which is
I have a simple UL navigation menu with width of 1000px: <ul class=menu> <li
I have a horizontal menu navigation. The code is: <div class=menu-holder> <ul class=menu> <li>

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.