I'm currently developing a website with a striking layout featuring 'hero' panels that cascade down the home page, showcasing text overlaid on captivating background images.
My goal is to utilize inline images with srcset
and sizes
attributes in order for the browser to select the most suitable image based on screen size rather than simply inserting the largest image possible as a background-image
and scaling it down for smaller screens.
At this point, here's what my code looks like:
<img
src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
srcset="/img/trekking_320.jpg 320w,
/img/trekking_480.jpg 480w,
/img/trekking_600.jpg 600w,
/img/trekking_768.jpg 768w,
/img/trekking_960.jpg 960w"
data-sizes="100vw"
class="lazyload"
>
along with CSS:
img {
position: absolute;
height: 100%; width: auto;
}
with overflow:hidden
set on the container element.
The image heights range from 320px to 768px, then 480px up to 960px, followed by a max-height of 600px beyond that.
I've prepared a Codepen demonstration to showcase the issue. While everything functions smoothly on high-resolution screens across various devices (mobile, tablet, laptop) and even on standard dpi displays up to 768px wide, there seems to be an issue with the images not filling the screen past that point.
Given the circumstances, I'm left pondering if it's feasible to achieve all the mentioned requirements outlined in the title. Am I heading in the right direction, or should I explore an entirely different approach?