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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:31:24+00:00 2026-05-15T01:31:24+00:00

I have a css horizontal menu with a menu / submenu display working on

  • 0

I have a css horizontal menu with a menu / submenu display working on the hover, but I would also like to make the submenu options stay put when I’ve selected that page. The code below shows the submenu on hover, but goes away on mouse out. I’m having some difficulty figuring out how to make my code work to keep the submenu items staying put? How can I do this?

Thanks for your help.

Here’s the HTML:

<ul id="menu_nav">
    <li>
        <a href="#" class="button">Home</a>
        <span>
            <a href="#">Home Link1</a> 
            <a href="#">Home Link2</a> 
            <a href="#">Home Link3</a>
        </span>
    </li>
    <li>
        <a href="#" class="button">About Us</a>
        <span>
            <a href="#">About Link1</a> 
            <a href="#">About Link2</a> 
            <a href="#">About Link3</a>
        </span>
    </li>
</ul>

Here’s the CSS

ul#menu_nav
{
    position:relative;
    float:left;
    width:790px;
    padding:0;
    margin:0;
    list-style-type:none;
    background-color:#000099;
}
ul#menu_nav li {float: left;
    margin: 0; padding: 0;
    border-right: 1px solid #555;}

ul#menu_nav li a.button
{
    float:left;
    text-decoration:none;
    color:white;
    background-color:#000099;
    padding:0.2em 0.6em;
    border-right:1px solid #CCCCCC;

    font-family: Tahoma;
    font-size: 11px;
    font-style: normal;
    font-weight: bold;
    position: relative;
    height: 21px;
    line-height:1.85em;
}
ul#menu_nav li a:hover {
    background-color:#F7F7F7;
    color:#000099;
    border-top:1px solid #CCCCCC;
}

ul#menu_nav li span{
    float: left;
    padding: 15px 0;
    position: absolute;
    left: 0; top:25px;
    display: none; /*--Hide by default--*/
    width: 790px;
    background: #F7F7F7;
    color: #fff;
}
ul#menu_nav li:hover span { display: block; } /*--Show subnav on hover--*/
ul#menu_nav li span a { display: inline; } /*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#menu_nav li span a:hover {text-decoration: underline;}

Heres the jquery:

$("ul#menu_nav li").hover(function() { //Hover over event on list item
        $(this).css({ 'background' : '#1376c9'}); //Add background color and image on hovered list item
        $(this).find("span").show(); //Show the subnav
    } , function() { //on hover out...
        $(this).css({ 'background' : 'none'}); //Ditch the background
        $(this).find("span").hide(); //Hide the subnav
    });
  • 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-05-15T01:31:25+00:00Added an answer on May 15, 2026 at 1:31 am

    Bryan, thanks. I basically did something to what you suggested. I already had a class called “.selected”, which was used to display the selected tab for the menu. in the “hover” event I put an if statement to check to see if the class had “selected” in it, if so, I simply displayed the hidden span tag. “$(this).next().show();” is the line that did what I needed on the “click” event to make the submenu stay put. Hope it helps anyone else.

    See the code:

    $("ul#menu_nav li").hover(function() { //Hover over event on list item
                $(this).css({ 'background' : '#1376c9'}); //Add background color and image on hovered list item
                $(this).find("span").show(); //Show the subnav
            } , function() { //on hover out...
                $(this).css({ 'background' : 'none'}); //Ditch the background
    
                if( $(this).children("a").is('.selected') ) 
                {
                    $(this).children("span").show();
                } 
                else 
                {
                    $(this).find("span").hide(); //Hide the subnav
                }
            });
    
            $(".menu_buttons li>a").click(function(){
                $(this).addClass('selected').removeClass('button')
                        .parents().siblings().children("a").removeClass('selected').addClass('button')
                        .parents().siblings().children("span").hide()
                $(this).next().show();
            }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're willing to sacrifice IE 6 compatibility, you can… May 16, 2026 at 11:52 am
  • Editorial Team
    Editorial Team added an answer Your SQL says: for each row in videocodec, select all… May 16, 2026 at 11:52 am
  • Editorial Team
    Editorial Team added an answer Use a spatial data structure to efficiently look up units… May 16, 2026 at 11:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a menu working fairly well but can't figure out how to make
I have been trying to make the sub-menu horizontal. In my HTML it looks
I have a horizontal css menu with 5 items. e.g 1) Home 2) Users
I currently have a drop-line horizontal menu using an unordered list with the following
I have a horizontal menu bar made up of <li> tags, containing links, so
My CSS looks like this: #menu { width: 1024px; height: 25px; margin: 0 auto;
I'm trying to create a two-level horizontal navigation menu (or menubar) that displays the
I'm trying to build a simple multi-level UL Horizontal Accordion (or slide menu) in
I have the following code: CSS #main { width:100%; height:120px; border:solid 1px #efefef; }
I have a text box and a button, which is described with the HTML/CSS

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.