0

I am getting a bunch of image URLs and I am displaying them in my webpage. By default I set all the images to have <img height = "200px" width = "200px">

The issue with this is that some images don't scale and look squished, how do I dynamically scale each image so that it doesn't look squished but is smaller. For example if I have a picture that is 16:9 I'd like it to keep that ratio when making it smaller.

1 Answer 1

1

So, you want an image to have width and height of 200px, while maintaining aspect ratio.

If you set height and width in html, it will lead to image not maintaining the aspect ratio. Instead use CSS.

<img class="myImg" />

In styles.css
.myImg {
    max-width: 200px;
    max-height: 200px;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.