html - Image + Text in DIV and keep aspect ratio -


i have following requirements:

  • i need div image + text inside.
  • the div should keep aspect ratio , images inside of divs should have same height (to this, use: maintain aspect ratio of div css).
  • the image inside of div should stretched in order fill parent div.

i prepared jsfiddle

i have 2 main issues:

  • as can see, left div higher, because has text inside. collides padding-bottom: 150%-approach used preserve aspect ratio of divs when size changed. goal, however, divs have same size no matter if/how text have inside.
  • moreover, change opacity of background image when hover div. however, text-opacity should not change. think can achieved via js. how?

add text position:absolute

.inner-text{   position:absolute;   width:100%;   height:100%;   text-align:center;   z-index:1; } .event:hover .inner-text{   background:rgba(255,255,255,0.5) }   <div class="bit-3">   <div class="event" style="background-image: url(https://container25.at/wpdev/wp-content/uploads/2016/06/test.jpg)">   <div class="inner-text">       text inner   </div>   </div> </div> 

update fiddle code: https://jsfiddle.net/f5uxz4mx/8/


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -