简体   繁体   中英

Image fill parent div width and height wise, and center

I am loading a rather large image into the parent div and my pug code is as follows:

a.eventlist-column-thumbnail.content-fill(href=`${link}`)
    img(src=`${img_src}`, alt=`${img_src}`, style='position: static; float:left; width: 100%;')

The point here is that with width: 100% I am able to fill the parent w/ the following effect:

rand-walk-2.png

This isn't bad however as you look closely, you'll see that the image does not fill the height, because aspect ratio wise it is "skinnier" than the parent div.

I would like to achieve this effect where the image fills the width and height as conservatively as possible while remaining centered relative to parent div:

rand-walk-3.png

Not very familiar with html/css , so please give pointers.

You can set width: 100%; and fixed height - in pixels: height: --px;

— — https://jsfiddle.net/ge5o91vg/4/

try object-fit: cover; in img tag

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