html - How to inherit photo when hover on links under navigation bar? -


i made navigiation bar changes photo on hover. works when hover on links (first level menu) when hover on dropdown's (second level menu) photo goes off. how make photo stay when hover on both main menu , submenu (dropdown). photo should not disappear when hover on submenu.

i achieve without using javascript, purely css.

nav{      background-color: #fff;      width:150px;      height: 667px;      float:right;  }    nav h1{      padding: 20px;      color: #777;      font: 20px tahoma,times,serif;    }  ul {   position: relative;   margin: 0;   padding: 0;   list-style: none;   width: 150px;   text-align: right;   }  ul li {   position: relative;   }  li ul {   position: absolute;   right: 149px;   top: 0;   display: none;   }  ul li {   display: block;   text-decoration: none;   color: #777;   background: #fff;   padding: 5px;     border-bottom: 0;   }  ul {   margin: 0;   padding: 0;   list-style: none;   width: 150px;     }  li:hover ul {       display: block;  }    * {      margin: 0;      padding: 0;  }  body {      background: #333;      background: url("http://vignette1.wikia.nocookie.net/logopedia/images/6/69/fc-barcelona-old-logo.png/revision/latest?cb=20120211172615");      background-repeat: no-repeat;  }    .container{      overflow: hidden;      margin-right: 0;      height: 500px;       -webkit-box-shadow: 10px 10px 10px rgba(0,0,0,0.3);      box-shadow: 10px 10px 10px rgba(0,0,0,0.3);      width: 800px;  }  .container img{      margin-top: 0px auto;      position: fixed;      top: 0px;      left: 0px;      z-index: -60;      height: 500px;      width: 800px;  }  .container li img {      opacity: 0.5;      margin-top: 0px auto;      position: absolute;      left: 0px;      z-index: -50;      -webkit-transition: 1s ease;      -moz-transition: 1s ease;      -o-transition: 1s ease;      -ms-transition: 1s ease;      transition: 1s ease;     }    li:nth-child(1){      padding-top: 0px;  }    li a:hover {      background: #eee;  }    li a:hover + img {      opacity: 1;      position: fixed;      margin-top: 0px auto;      left: 0px auto;      height: 500px;      width: 800px;  }
<!doctype html>    <html lang="en">      <head>          <meta charset="utf-8" />          <link rel=stylesheet type="text/css" href="stylesheet.css"/>          <title></title>      </head>      <body>          <div class="container">          <nav><h1><b>ברצלונה</b></h1>    <ul>    <li><a href="#">ברצלונה</a><img src="http://media3.fcbarcelona.com/media/asset_publics/resources/000/160/456/size_640x360/pic_2015-01-11_barcelona-atletico_45.v1431011244.jpg" alt="1"></li>     <li><a href="#">לה ליגה</a><img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:and9gctd6ngnngapdlhqds4kbuonncaaump4svu-e_9rxmh_wldtppse" alt="1">        <ul>         <li><a href="#">ברצלונה</a></li>         <li><a href="#">ריאל</a></li>         <li><a href="#">אתלטיקו</a></li>         </ul>              </li>     <li><a href="#">בונדסליגה</a><img src="http://static3.demotix.com/sites/default/files/imagecache/a_scale_large/2000-5/photos/1368393557-club-atletico-de-madrid-v-fc-barcelona--la-liga_2046465.jpg" alt="1">         <ul>         <li><a href="#">באיירן</a></li>         <li><a href="#">וולפסבורג</a></li>         <li><a href="#">הנדובר</a></li>         <li><a href="#">דורטמונד</a></li>          </ul>       </li>    <li><a href="#">סיירה א</a><img src="http://barcelonacamps.com/wp-content/uploads/2014/04/barca-new-team.jpg" alt="1">         <ul>         <li><a href="#">אינטר</a></li>         <li><a href="#">מילאן</a></li>         <li><a href="#">יובה</a></li>         <li><a href="#">רומא</a></li>         </ul>         </ul>      </li>               </nav>          </div>       </body>  </html>

see fiddle

just below slight change in css..

replace

li a:hover + img {     opacity: 1;     position: fixed;     margin-top: 0px auto;     left: 0px auto;     height: 500px;     width: 800px; } 

with

li:hover +img {   opacity: 1;   position: fixed;   margin-top: 0px auto;   left: 0px auto;   height: 500px;   width: 800px; } 

also, <li> , <ul> tags not closed @ end. bring </li> before </ul>.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -