Note that there are some explanatory texts on larger screens.

plurals
  1. POActive Menu Highlight CSS
    primarykey
    data
    text
    <p>I want to highlight the current menu you have click. I'm using CSS, but it is now working.</p> <p>here is my css code:</p> <pre><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; } </code></pre> <p>here is my html:</p> <pre><code>&lt;div id="sub-header"&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="index.php"&gt;Home&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="contact.php"&gt;Contact Us&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="about.php"&gt;About Us&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>This is what I like when I hover and if the menu is active</p> <p><img src="https://i.stack.imgur.com/h6yKf.png" alt="This is what I like when I hover and if the menu is active"></p> <p>Hover is okay, The problem is when I after click the menu the black ground is not display</p> <hr> <p>@Jonathan, I have already solve it and it is more simply than what you have gave.</p> <p>this is my answer:</p> <pre><code>$(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"); } }); }); </code></pre> <p>then on my css file:</p> <pre><code>.active { background-color: #000; } /* to override the existing css for "a" tag */ #sub-header .active a{ color: #fff; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload