I have an image 500x348px which has a lot of white space around it that I wish to display without the white space.
It comes form an API so I can’t edit it.
I thought I needed to use clip-path: polygon(23% 1%, 77% 1%, 77% 41%, 23% 41%); This hides all the white space (plus a bit more) but the image still takes up the whole 500x348px. Can I make it so the image only takes up the space of the clipped area? I tried overflow: hidden; without success.
Another option would be to stick it inside a container with the desired width and height and position the image inside that div with object-fit / object-position.
As an example, if the part of the image you wanted to show was 360px x 240px and there was 40px of whitespace on the top and left, you could place the image in a div and use CSS like this:
Thanks, chaps. Actually, it looks like the usual trick of changing width to max-width and height to max-height and adding width: 100% and height: autoalmost works.