A
A
Alexey Nikashkin2015-05-04 19:39:15
css
Alexey Nikashkin, 2015-05-04 19:39:15

How to change the background of the active item in the menu?

How to make the background of an item in the menu appear when we are on a particular page. For example, we are on the 'Home', and in the menu the background of the 'Home' has changed. For example, as in the menu of this site.
The active item is the item that points to the page we are on.
P.S. I'm sorry for explaining so badly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sasha, 2015-05-04
@IncludeURL

It can be implemented in Javascript if it's just layout, without using CMS.
If this is a CMS, then it has an active class on the navigation item related to different pages.
js will look like this

var urlNow = window.location.pathname.split('/').join(' ');
$(".nav a").each(function(){
  var hrefLink = $(this).attr('href');
  var findConsilience = urlNow.indexOf(hrefLink);
  if(findConsilience > 0){
    $(this).addClass('item-active');
  }
});

html so
url
somesite/contacts.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question