html - How to use picture element for sharp images on mobile -


picture element getting , spread (http://caniuse.com/#search=picture), , think great way avoid serving oversized/undersized pictures, specially when want display same picture on mobile , desktop @ 100% of viewport width.

that can solved this:

<img     srcset="large.jpg  1920w,              medium.jpg  720w,             small.jpg   360w"     src="medium.jpg"> 

this allows browser clever , decide picture load, find problem approach: many mobile devices have pixel density of 2 or more! therefore when displaying 360w need medium image if want image sharp. done this:

<picture>     <source srcset="http://goo.gl/lsuu9t" media="(min-width: 720px)">     <source srcset="http://goo.gl/lsuu9t" media="(min-width: 360px , min-resolution: 2dppx)">     <img src="http://goo.gl/lsuu9t">  </picture>

the problem here, in opinion, can grow as screen resolution grows , lose benefits of browser cleverly deciding best option.

so, question if there halfway point between two, can still separate between html , css.

the browser takes pixel density account when selecting image. device 360 css px wide viewport , 2x pixel density select medium.jpg. w descriptor , sizes attribute designed solve! don't use picture here.

also see https://ericportis.com/posts/2014/srcset-sizes/


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -