html - Set different color to parent menu item after hovering over submenu -


i have menu submenu using css , html.

i'm trying make main menu color when mouse on it..

and keep change while mouse on submenu..

all can set same color os submenu..

here i'm trying do:

foto

my code:

html:

<ul id="nav">     <li><a href="#">home</a></li>     <li>       <a href="#">institucional</a>       <ul>          <li><a href="#">nonononono</a></li>          <li><a href="#">nonononono</a></li></li>          <li><a href="#">nonononono</a></li>       </ul>    </li> </ul> 

css:

#nav{     list-style:none;     font-weight:bold;     float:right;     width:100%;     font-size:13px; }  #nav li{     float:left;     margin-right:10px;     position:relative;     text-align:left; }  #nav a{     display:block;     padding:5px;     color:#666;     text-decoration:none;     //background:white; } #nav a:hover{     color:yellow;     text-decoration:none;     background:#d93600; }  #nav ul{     //border:1px solid black;     border-top:0;     border-right:0;     background:#d93600;     list-style:none;     position:absolute;     left:-9999px;     -webkit-box-shadow: 3px 3px 3px 0px rgba(50, 50, 50, 0.75);     -moz-box-shadow:    3px 3px 3px 0px rgba(50, 50, 50, 0.75);     box-shadow:         3px 3px 3px 0px rgba(50, 50, 50, 0.75); } #nav ul li{     padding-top:1px; /* introducing padding between li , give illusion spaced items */     float:none;     border-bottom:1px solid #ff7040;     margin-right:0px; } #nav ul a{     white-space:nowrap; /* stop text wrapping , creating multi-line dropdown items */     text-decoration:none; } #nav li:hover ul{ /* display dropdown on hover */     left:0; /* bring on-screen when needed */ } #nav li:hover a{ /* these create persistent hover states, meaning top-most link stays 'hovered' when cursor has moved down list. */     //background:#d93600;     text-decoration:none; } #nav li:hover ul a{ /* persistent hover state create global style links before they're hovered. here undo these effects. */     text-decoration:none;     color:white;     font-weight:normal;     font-size:12px; } #nav li:hover ul li a:hover{ /* here define explicit hover states--what happens when hover each individual link. */     background:#ffbe13;     text-decoration:none;     color:black; } 

just apply :hover effect full li element

#nav > li:hover {    background-color: #d93600;    color: yellow;  }  #nav > li:hover {    color: yellow;  }  /* rest of code */    #nav {    list-style: none;    font-weight: bold;    float: right;    width: 100%;    font-size: 13px;  }  #nav li {    float: left;    margin-right: 10px;    position: relative;    text-align: left;  }  #nav {    display: block;    padding: 5px;    color: #666;    text-decoration: none;    //background:white;    }  #nav a:hover {    color: yellow;    text-decoration: none;    background: #d93600;  }  #nav ul {    //border:1px solid black;    border-top: 0;    border-right: 0;    background: #d93600;    list-style: none;    position: absolute;    left: -9999px;    -webkit-box-shadow: 3px 3px 3px 0px rgba(50, 50, 50, 0.75);    -moz-box-shadow: 3px 3px 3px 0px rgba(50, 50, 50, 0.75);    box-shadow: 3px 3px 3px 0px rgba(50, 50, 50, 0.75);  }  #nav ul li {    padding-top: 1px;    /* introducing padding between li , give illusion spaced items */    float: none;    border-bottom: 1px solid #ff7040;    margin-right: 0px;  }  #nav ul {    white-space: nowrap;    /* stop text wrapping , creating multi-line dropdown items */    text-decoration: none;  }  #nav li:hover ul {    /* display dropdown on hover */    left: 0;    /* bring on-screen when needed */  }  #nav li:hover {    /* these create persistent hover states, meaning top-most link stays 'hovered' when cursor has moved down list. */    //background:#d93600;    text-decoration: none;  }  #nav li:hover ul {    /* persistent hover state create global style links before they're hovered. here undo these effects. */    text-decoration: none;    color: white;    font-weight: normal;    font-size: 12px;  }  #nav li:hover ul li a:hover {    /* here define explicit hover states--what happens when hover each individual link. */    background: #ffbe13;    text-decoration: none;    color: black;  }
<ul id="nav">      <li><a href="#">home</a>    </li>      <li>      <a href="#">institucional</a>      <ul>        <li><a href="#">sobre o ccocf</a>        </li>        <li><a href="#">assosiação de amigos ccocf</a>        </li>    </li>    <li><a href="#">projetos da casa</a>    </li>    </ul>    </li>  </ul>