css - hover over photo wont add transparent div -


i'm trying add transparent text overlay on top of image. i've decided using css add transparent div easiest, can't figure out why code isn't working. changed opacity of image when hovering on , set div containing text visibility:hidden. used hovereffect make visibility:visible. can't work though. please help. here's fiddle:

https://jsfiddle.net/3lx1pyl9/

here's html:

<div id="chickcontainer">          <img src="http://animal-dream.com/data_images/chicken/chicken7.jpg"><div class="overlay">chicks</div>         <img class="chicks" src="https://smittenkitchendotcom.files.wordpress.com/2016/09/piri-piri-chicken.jpg?w=750">         <img class="chicks" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:and9gcrzrjv4ilzyh0eqyvg9-oidaw1t24xa_vmvrx4qy-woymigpcx6">     </div> 

and css:

#chickcontainer img{     position:relative;     width:30%;     height:30%;     display:inline-block;     margin-left:2%;     border-radius:100%;     border: solid .5px;  }  .overlay{     visibility:hidden;     position:absolute;     width:20%;     height:90%;     top:12%;     left:7%;     z-index:0; }  #chickcontainer img:hover .overlay{     visibility:visible;     z-index:100; } 

the problem selector:

#chickcontainer img:hover .overlay 

this selector expects .overlay descendent of img:hover , images not able have descendants @ all. in html, .overlay sibling sits next image.

<img src="http://animal-dream.com/data_images/chicken/chicken7.jpg"><div class="overlay">chicks</div> 

instead, should use "next sibling" + selector select next element , apply style it.

#chickcontainer img:hover + .overlay 

here's working example

#chickcontainer img{      position:relative;      width:30%;      height:30%;      display:inline-block;      margin-left:2%;      border-radius:100%;      border: solid .5px;    }    .overlay{      visibility:hidden;      position:absolute;      width:20%;      height:90%;      top:12%;      left:7%;      z-index:0;  }    #chickcontainer img:hover + .overlay{      visibility:visible;      z-index:100;  }
<div id="chickcontainer">      <img src="http://animal-dream.com/data_images/chicken/chicken7.jpg"><div class="overlay">chicks</div>      <img class="chicks" src="https://smittenkitchendotcom.files.wordpress.com/2016/09/piri-piri-chicken.jpg?w=750">      <img class="chicks" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:and9gcrzrjv4ilzyh0eqyvg9-oidaw1t24xa_vmvrx4qy-woymigpcx6">  </div>


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -