html - How to change parent li color on child ul hover -


i have menu structured in following way, , i'm trying give previous li background change when hovering on nested li.

<ul class="level0">    <li class="level1">nav item</li>    <li class="level1">nav item</li>    <ul class="level1">       <li class="level2">nav item</li>       <li class="level2">nav item</li>       <li class="level2">nav item</li>    </ul>    <li class="level1">nav item</li>    <li class="level1">nav item</li> </ul> 

on ul.level1:hover highlight li.level1

is possible css/sass alone?

edit: example added http://codepen.io/curiouscrusher/pen/avpebz?editors=110

you add 'parent' class parent, , add rule child, parent, not super efficient though:

nav {    .parent{       color:black;    }    ul:hover{        .parent{          color:red;        }      }    li {      padding: .5em 0;      &:hover {        cursor: pointer;        font-weight: bold;      }    }  }
<nav>    <ul class="level0">       <li class="level1">nav item</li>       <li class="level1 parent">make li change</li>       <ul class="level1">          <li class="level2">when hovering here</li>          <li class="level2">nav item</li>          <li class="level2">nav item</li>       </ul>       <li class="level1">nav item</li>       <li class="level1">nav item</li>    </ul>  </nav>


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -