I want to make an overlay for the picture. Came up with this layout:

<div id="parent"> <img/> <div id="children"></div> </div> 

css:

 img {width: 100%;} 

Tell me how to set the height of div # children, so that it would be equal to the height?

  • Preferably without scripts. - Denni Adam
  • one
  • @ soledar10, thanks! If issue as an answer - put a tick) - Denni Adam

1 answer 1

 img { width: 100%; max-width: 100%; height: auto; } .parent { max-width: 400px; margin: 15px auto; position: relative; line-height: 0; } .children { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); line-height: 1; opacity: 0; transition: 0.3s; } .parent:hover .children{ opacity: 1; } 
 <div class="parent"> <img src="http://placehold.it/250x150" alt=""> <div class="children"></div> </div>