html5 - img srcset based on img width rather than viewport width -


i have partial template renders article on page image , accompanying text. in landing page have several articles on page, varying classes, lead article full width, secondary articles half with, tertiary 3rd width. sidebar articles have small widths. , depending on viewport, image can rendered above text or left of it.

in summary same article html renders in many ways depending on context.

is there way account in latest srcset spec?

from can tell have have different sizes attribute per context, coupling layout/breakpoint markup in implementation many contexts, make server side logic horrid.

the width descriptor in srcset defines width of image not viewport.

in case mean sizes attribute:

in short can't. reason is, browser starts fetch images before might loaded/parsed stylesheets. means layout isn't known. if use lazyloading techniques can automatically calculate sizes attribute.

this done lazysizes.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -