Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set parent link active if child or grandchild link is active using CSS

I have a HTML/CSS menu with this CSS for the active links:

.navigation ul li a:hover, .navigation .active-nav {
    background-color: #F36F25; /*#373737;*/
    text-shadow: none;
    color: #f7f7f7 !important;
    -webkit-box-shadow: 0 3px 0 #ff8833;
    box-shadow: 0 3px 0 #ff8833;
}

Fiddle: http://jsfiddle.net/kyvbzssd/

How can I set the top parent link as active if any of its child or its child's child links have an active class?

like image 526
charlie Avatar asked Jun 28 '15 11:06

charlie


1 Answers

Add the style to your li element as well : http://jsfiddle.net/kyvbzssd/3/

.navigation ul li{
    padding: 80px 9px 10px;
}
.navigation ul li a,.navigation ul li{
    font-size: 13px;
    font-weight: 700;
    color: #4d4d4d;
    text-decoration: none;
    display: inline-block;
    margin-bottom: 0;
    text-transform: uppercase;
    border-bottom: 2px solid #fff;
    -webkit-transition: background-color .2s linear, padding-top .2s linear;
    -moz-transition: background-color .2s linear, padding-top .2s linear;
    -o-transition: background-color .2s linear, padding-top .2s linear;
    -ms-transition: background-color .2s linear, padding-top .2s linear;
    transition: background-color .2s linear, padding-top .2s linear;
}
.navigation ul li a:hover,.navigation ul li:hover,.navigation .active-nav {
    background-color: #F36F25; /*#373737;*/
    text-shadow: none;
    color: #f7f7f7!important;
    -webkit-box-shadow: 0 3px 0 #ff8833;
    box-shadow: 0 3px 0 #ff8833;
}
like image 149
loli Avatar answered Sep 27 '22 17:09

loli