It works for me but only if I go from narrow to wide - not the other way round. If I make the page 226px wide using Chrome’s device mode in the dev tools and reload the page then the small image is displayed. Increasing the width from there to 404px displays the medium image, and anything above that will display the large image. It seems odd that it only works from small to large – displaying a wide angle shot at wider sizes and drilling down to a more detailed shot at smaller ones seems like it would be useful.
You can get better control over when to display the images using the sizes attribute. Using the following will get you something that seems to be pretty close:
sizes="(max-width: 320px) 50vw, (max-width: 768px) 70vw, 282px"
Broken down, the first part says that at 320px wide and lower the image will be 50% of the viewport width, so the small image will be display at anything 320 and below. At 320–768 it will be 70% of the viewport width, so the medium one is used between 320–500(ish) and then the large one will be displayed. Anything above 768 and the image will always be 282px wide so the medium image is used.
For better high-dpi results you can remove the 320 query and up the 768 one to 100vw.
I found this article (and the subsequent one) provided an easier to follow description of srcset and sizes than the CSS Tricks one: Responsive Images 101, Part 4: Srcset Width Descriptors – Cloud Four
Joe
On 12 Jul 2015, at 09:17, The Big Erns email@hidden wrote:
My first attempt at the srcset
attribute has given me mixed results.
I was able to get 2x images to show on retina displays (Safari and iOS) while only showing 1x images on regular displays.
But when it came to serving large, medium, small images in the appropriate circumstances, I could only and always ever get the large version to show (this aspect of secretes is only supported in Chrome and Firefox, currently).
I look forward to your comments and speculation about the source of my partial failure, and what you might think of the whole thing anyway.
http://cssway.thebigerns.com/workbench/srcset-first-attempt/
freewaytalk mailing list
email@hidden
Update your subscriptions at:
Information for existing FreewayTalk / Groups.io users - Site Feedback - Softpress Talk
freewaytalk mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options