CSS scale and square center crop image

前端 未结 3 1519
甜味超标
甜味超标 2021-02-02 08:43

So I have a collection of thumbnails in my app, which is the size of 200x200. Sometimes the original image doesn\'t have this ratio so I am planning to crop this image

3条回答
  •  天涯浪人
    2021-02-02 09:11

    You can do this easily in CSS if you use background-image.

    .thumb {
        display: inline-block;
        width: 200px;
        height: 200px;
        margin: 5px;
        border: 3px solid #c99;
        background-position: center center;
        background-size: cover;
    }
    

    In this fiddle, first image is 400x800, second image is 800x400:

    http://jsfiddle.net/samliew/tx7sf

提交回复
热议问题