How to center crop an image ()

后端 未结 4 1952
太阳男子
太阳男子 2020-12-22 16:40

How do I get an image to stay centered when its fluid width (percentage based) container is too small to show the whole image?

4条回答
  •  礼貌的吻别
    2020-12-22 17:26

    I had the same problem but the solutions here didn't help me (because I'm displaying inside a table and because I wanted the image to change without having to scale it manually every time as the image was sent by clients)

    Here's what I found, much more effecitve and easier :

    img {
     object-fit: cover;
     width: 150px;
     height: 150px;
     }
    

提交回复
热议问题