I need to always crop a random-sized image to a square 160x160 using only CSS.
The images should stay centered when cropped.
My markup should be:
<a href="#" class="cropper">
<img src="image" alt="description" />
</a>
Searching on StackOverflow I've found some answers (such as CSS - How to crop an image to a square, if it's already square then resize it), but they don't work for cases where your image can be larger horizontal (wide) OR vertical (tall).
Specifically, I need to be able to present both a wide image like this:
and a tall image like this:
in square form, without knowing in advance which one is a horizontal rectangle or a vertical rectangle. It should also support already squared images.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…