I want to make an image width the same as the viewport width for any device, however, it should shrink or grow if someone zooms in or out
I've tried setting the html element font size and then setting the image to a slightly bigger-than-the-viewport size in rem. Then, to make sure it doesn't get bigger than the viewport, I've set max-width: 100%. This works great for any device size and also when zooming out, however bugs pretty bad when zooming in and does not work at all.
Is there any way to disable the max-width rule when zoom level is above 100%? Or perhaps there is a better way of doing this that doesn't involve rem?
Here is the code I'm using:
html {
font-size: 10px;
}
.section {
margin: 0;
width: 160rem;
max-width: 100%;
}
.section>img {
width: 100%;
}
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<section class="section">
<img src="https://photographylife.com/wp-content/uploads/2017/07/Hasselblad-X1D-50c-Image-Sample-10.jpg" alt="Image">
</section>
</body>
</html>
To witness the effect run the snippet in "full page" and try zooming in