Making all photos square via css

后端 未结 6 1968
忘掉有多难
忘掉有多难 2021-02-07 06:50

I\'m trying to make a series of photos into square photos. They may be rectangular horizontally (i.e. 600x400) or vertically (400x600), but I want to get them to be 175x175 eit

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 07:08

    You can use object-fit, which is widely supported in all major browsers. When set to cover, the browser will crop the image when you set the width and height properties, rather the stretching it.

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

提交回复
热议问题