简体   繁体   中英

How to align images in card with dynamic title?

I will have several different cards with dynamic titles coming from the backend. What I need is to align pictures in a same line, no matter how long the title is, it should be aligned based on the longest title. Here is the picture bellow what I need, and here is the JSfiddle link to the code so far.

This is how it should look like

 .wrapper { width: 100%; display: flex; }.card{ text-align: center; width: 33%; background: pink; margin-right: 10px; padding: 20px 5px; }.image { margin-top: 20px; }
 <div class="wrapper"> <div class="card"> <div class="head"> <div class="title"> Hello </div> <div class="image"> <img src="https://www.freepnglogos.com/uploads/netflix-red-logo-circle-png-14.png" /> </div> </div> </div> <div class="card"> <div class="head"> <div class="title"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div> <div class="image"> <img src="https://www.freepnglogos.com/uploads/netflix-red-logo-circle-png-14.png" /> </div> </div> </div> </div>

You need to incorporate flexbox into the children and then force the image to always be at the bottom of the column.

Note ...this only works when there are two children...aligning multiple children is not fully supported see Align child elements of different blocks

 .wrapper { width: 100%; display: flex; }.card { text-align: center; width: 33%; background: pink; margin-right: 10px; padding: 20px 5px; display: flex; flex-direction: column; }.title { flex: 1; }.image { margin-top: auto; }.head { display: flex; flex: 1; flex-direction: column; }
 <div class="wrapper"> <div class="card"> <div class="head"> <div class="title"> Hello </div> <div class="image"> <img src="https://www.freepnglogos.com/uploads/netflix-red-logo-circle-png-14.png" /> </div> </div> </div> <div class="card"> <div class="head"> <div class="title"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </div> <div class="image"> <img src="https://www.freepnglogos.com/uploads/netflix-red-logo-circle-png-14.png" /> </div> </div> </div> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM