Apply CSS as URL

0

When I'm in / start the CSS header nav ul li .submenu should be top: 300px , other pages should be top: 120px in>. I put inside the $ (document) .ready (function () {}); the following expression:

$("a[href='/inicio]").find("header nav ul li .submenu").css("top", "300px!important");

But it is not working. The CSS looks like this:

header nav ul li .submenu {
    background: #f3f3f3;
    border-top: 2px solid #ffae11;
    border-radius: 3px;
    box-shadow: 0 8px 12px rgba(0,0,0,0.2);
    display: none;
    font-size: 0;
    padding: 15px 25px;
    position: absolute;
    top: 120px;
    left: 0;
    width: 100%;
    margin-left: 0;
    z-index: 2000;
}
    
asked by anonymous 20.10.2017 / 14:51

1 answer

1

Well, let's try to solve it in an easy way, okay?

I believe this / home is the main page of your correct site?

So you've created an instruction that detects whether or not the home page is over the link. Let's make a change in that? Let's go.

To detect whether or not the main page you can add this information to the <body> tag of your page! Here's the example.

no HTML add:

<body class='principal'>

I particularly prefer working with classes

Well, now in Jquery we will do a function that looks for the information present in the body. See:

$(document).ready(function(){

   if($('body').hasClass('principal')) 
   {
      $("header nav ul li .submenu").css("top", "300px");
   }

});
    
20.10.2017 / 15:07