In a page with some navigation links,I want the link of the current page are hightlighted,just like this:
The link "HTML Attributes" is highlighted(bolded) since this link will take one to the current page.
I know this can be implemented manually(just hightlighted the according link,but is there some smart way? highlight the right link dynamically and automatically?
Highlighting the current page makes navigation easier. WordPress menu functions (wp_nav_menu, wp_list_pages) automatically add current_page_item class to li containing the active link. So all we have to do is use the same class to highlight the current page.
The :active selector is used to select and style the active link. A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links.
Create a new menuIn the left sidebar menu, navigate to Website > Navigation. Your default menu contains the pages that will automatically populate the default content of an advanced menu module. Use the dropdown menu to select an existing menu to update. To create a new menu, click + Add menu.
CSS:
.topmenu ul li.active a, .topmenu ul li a:hover { text-decoration:none; color:#fff; background:url(../images/menu_a.jpg) no-repeat center top; }
JavaScript:
<script src="JavaScript/jquery-1.10.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { // this will get the full URL at the address bar var url = window.location.href; // passes on every "a" tag $(".topmenu a").each(function() { // checks if its the same on the address bar if (url == (this.href)) { $(this).closest("li").addClass("active"); //for making parent of submenu active $(this).closest("li").parent().parent().addClass("active"); } }); }); </script>
Html Code:
<div class="topmenu"> <ul> <li><a href="Default.aspx">Home</a></li> <li><a href="NewsLetter.aspx">Newsletter</a></li> <li><a href="#">Forms</a></li> <li><a href="#">Mail</a></li> <li><a href="#">Service</a></li> <li style="border:none;"><a href="#">HSE</a></li> <li><a href="#">MainMenu2</a> <ul> <li>submenu1</li> <li>submenu2</li> <li>submenu3</li> </ul> </li> </ul> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With