I have some image cards that each have an image and some text. The size of these cards are determined by the height of the image that they contain. If the viewport width is so small that the set height of the image would make the image overflow horizontally I would like the image to shrink so that it stays within the card/viewport
.card {
width: fit-content;
max-width: 100%;
background-color: lightgray;
padding: 1em;
}
img {
height: 13em;
}
<div class="card">
<img src="https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg?v=47faa659a05e" alt="random image...">
</div>
I know I can use a media query, but I would like to know if there's a better way to solve this.