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 ofdivs
should have same height (to this, use: maintain aspect ratio of div css). - the image inside of
div
should stretched in order fill parentdiv
.
i have 2 main issues:
- as can see, left
div
higher, because has text inside. collidespadding-bottom: 150%
-approach used preserve aspect ratio ofdivs
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
Post a Comment