I am trying to create an icon container that will display any image size (long or wide).
The image should correspond to the container with its smaller side, while additional functions will be located outside the container. Before applying overflow: hidden, it should work as follows.

This seems to be pretty easy to do with js, but I'm curious to find a css solution.
<div class="container"> <img src="test.png"/> </div> .container { width: 30px; height: 30px; } .container img { position: relative; left: 50%; top: 50%; transform: translateY(-50%) translateX(-50%); }
source share