css - Carousel, make a div within an item same height as sibling item's div -
i have responsive owl carousel (v2), each item or slide has image , below text of variable length, see image below:
as can seen, images bottom aligned same baseline, regardless of how text there is. i've done setting text div fixed height. problem is, if there 1 line of text, i'd have unnecessary space below carousel.
if allow div set own height, this:
so images no longer lined up.
html
<div> <img class='a4_diary_image' src='sizes/test.png'> <div class='owl_diary_desc'> a4 size, going on 2 lines </div> </div> <div> <img class='a5_diary_image' src='sizes/test.png'> <div class='owl_diary_desc'> a5 size </div> </div> <div> <img class='a6_diary_image' src='sizes/test.png'> <div class='owl_diary_desc'> a6 size </div> </div> </div>
css
.owl-carousel .owl-item { display: table-cell; float: none; text-align: center; vertical-align: bottom; border: 1px dashed grey; height: 100%; padding: 0px 10px; } .owl_diary_desc { font-size: 19px; border: 1px dashed red; margin-top:10px; } .a4_diary_image { max-width: 100%; max-height: 100%; margin-left: auto; margin-right: auto; } .a5_diary_image { max-width: 70%; max-height: 70%; margin-left: auto; margin-right: auto; } .a6_diary_image { max-width: 50%; max-height: 50%; margin-left: auto; margin-right: auto; }
straight html , css won't allow set equal heights based off siblings. using little jquery can achieved though.
$maxdesc; function equalize(){ $('.owl_diary_desc').each(function(i){ if ($(this).height() > $maxdesc) { $maxdesc = $(this).height();} }); $('.owl_diary_desc').each(function(i){$(this).height($maxdesc);}); }
when use this, move variable holder beginning of script. call function on document ready. i'll call on window resize function. if choose that, must call each function on object , reset height auto before recalling equalize function.
Comments
Post a Comment