Making all photos square via css

后端 未结 6 2100
忘掉有多难
忘掉有多难 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:12

    You can set the width/height of the parent div then set the child img tag to width:100%; height: auto;

    That will scale the image down to try to fit the parent with aspect ratio in mind.

    You can also set the image as a background-image on the div Then if you can use css3 you can mess with the background-size property. It's attributes are: contain, cover, or a specificed height (50%, 50%) (175px, 175px) You could also try to center the picture with background-position

提交回复
热议问题