I'm in a bit of a quandary: How can I ensure that an image resizes properly based on viewport size?
So, here's the challenge - I have an image that is 400 pixels wide and 400 pixels tall. My aim is for it to occupy only 90% of the width of the viewport (90vw) upon resizing the browser window. Currently, this is the CSS code I am using:
img {
width: 400px;
height: 400px;
}
@media screen and (max-width: 400px) {
img {
width: 90vw;
height: 90vh;
}
}
The hitch I've run into is that the image doesn't seem to adjust at all with this current setup.
If I replace width
with max-width
, only the width changes, leaving me with a distorted elliptical image due to the unadjusted height.
Is there a simple solution to rectify my issue?