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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:30:53+00:00 2026-06-04T07:30:53+00:00

I want to highlight the current menu you have click. I’m using CSS, but

  • 0

I want to highlight the current menu you have click. I’m using CSS, but it is now working.

here is my css code:

#sub-header ul li:hover{ background-color: #000;}
#sub-header ul li:hover a{ color: #fff; }
#sub-header ul li.active{ background-color: #000; }
#sub-header ul li.active a{ color: #fff; }

here is my html:

<div id="sub-header">
    <ul>
        <li> <a href="index.php">Home</a> </li>
        <li> <a href="contact.php">Contact Us</a> </li>
        <li> <a href="about.php">About Us</a> </li>
    </ul>
</div>

This is what I like when I hover and if the menu is active

This is what I like when I hover and if the menu is active

Hover is okay, The problem is when I after click the menu the black ground is not display


@Jonathan, I have already solve it and it is more simply than what you have gave.

this is my answer:

$(function(){
    // this will get the full URL at the address bar
    var url = window.location.href; 

    // passes on every "a" tag 
    $("#sub-header a").each(function() {
            // checks if its the same on the address bar
        if(url == (this.href)) { 
            $(this).closest("li").addClass("active");
        }
    });
});

then on my css file:

.active { background-color: #000; }
/* to override the existing css for "a" tag */
#sub-header .active a{ color: #fff; }
  • 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-04T07:30:54+00:00Added an answer on June 4, 2026 at 7:30 am

    Add a class to the body of each page:

    <body class="home">
    

    Or if you’re on the contact page:

    <body class="contact">
    

    Then take this into consideration when you’re creating your styles:

    #sub-header ul li:hover,
    body.home li.home,
    body.contact li.contact { background-color: #000;}
    
    #sub-header ul li:hover a,
    body.home li.home a,
    body.contact li.contact a { color: #fff; }
    

    Lastly, apply class names to your list items:

    <ul>
      <li class="home"><a href="index.php">Home</a></li>
      <li class="contact"><a href="contact.php">Contact Us</a></li>
      <li class="about"><a href="about.php">About Us</a></li>
    </ul>
    

    This point, whenever you’re on the body.home page, your li.home a link will have default styling indicating it is the current page.

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

Sidebar

Related Questions

I have a menu but I want to highlight current link with jquery. var
I'm building a jQuery based tree menu using jQuery sortable(). Here is my current
I have an XML document, want to do syntax highlighting. The code uses XPathDocument
I have a pretty standard CSS based dropdown menu. The main list is #mainNav
I have a table with rows in it. I want to highlight the different
I started using a diagnostic css stylesheet, e.g. http://snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/ One of the suggested rules
I want to highlight the current navigation state. Like if the hashchange is #home
updated question I want to highlight weeks of the datepicker that have the sum
I am working on a force directed graph in D3. I want to highlight
I have a tabbed setup on the page and I want to automatically make

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.