I have a responsive image (srcset) that should be displayed at a max-width of 30rem, and fill the viewport otherwise. For that purpose I have the following html:
<div class="Wrapper">
<img
src="//via.placeholder.com/250x150"
srcset="
//via.placeholder.com/100x150 100w,
//via.placeholder.com/250x150 250w,
//via.placeholder.com/500x150 500w,
//via.placeholder.com/750x150 750w,
//via.placeholder.com/1000x150 1000w,
//via.placeholder.com/1250x150 1250w,
//via.placeholder.com/1500x150 1500w"
sizes="(min-width: 30em) 30rem, 100vw"
>
</div>
With this css (there is more, but this is the minimum to reproduce):
html {
font-size: 24px;
}
img {
max-width: 100%;
}
.Wrapper {
margin: 0 auto;
max-width: 30rem;
background: red;
}
On my monitor (macbook retina) the image is displayed like so:
So it isn't filling the viewport. Even though the measurements should be correct. I suspect that it has something to do with a difference in measurement between rem and em, but I'm not exactly sure what's going wrong. Why isn't the image filling the container?
Jsfiddle here: https://jsfiddle.net/Ly80zohd/2/