Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Picture element does not seem to be supported by Chrome 52? Srcset not working

I just started a new webpage so there's not much markup to go over.

I set this down:

<picture>
    <source media="(min-width: 1000px)"
            srcset="images/largeme.jpg">
    <source media="(min-width: 465px)"
            srcset="images/medme.jpg">
    <img src="images/smallme.jpg"alt="hero profile">
</picture>

and it defaults to the medme.jpg picture no matter the width of the window. I set down this:

<picture>
    <source media="(min-width: 1000px)"
            srcset="images/largeme.jpg">
    <source media="(min-width: 465px)"
            srcset="images/medme.jpg">
   <!-- <img src="images/smallme.jpg"alt="hero profile">-->
</picture>

commenting out the img fallback tag and it doesn't show anything.

I'm running Chrome 52 which should support picture element. But it seems to be acting as if it doesn't support it or something. What am I doing wrong here?

like image 909
David A. French Avatar asked Aug 30 '16 19:08

David A. French


People also ask

What is Srcset in html5?

srcset defines the set of images we will allow the browser to choose between, and what size each image is. Each set of image information is separated from the previous one by a comma.

Why is my photo tag not working?

If there is no img element nested inside the picture element, the picture element won't work. Like the srcset attribute, the picture element will update the value of the src attribute in that img element.

Does Srcset load all images?

Each image in srcset can be taken. So if you want to control, what is used or not used, you need to use the picture element.

Do you need SRC with Srcset?

Yes it's valid. The src is used as a fallback if the browser doesn't support srcset. However if you are using it just for retina stuff you don't really need to use picturefill. I tend to just let it degrade back to the normal src if the browser doesn't support srcset.


1 Answers

It sounds silly, but have you tried reverting the order? For some reason doing this made it work for me.

So, instead of:

<picture>
    <source media="(min-width: 1000px)"
            srcset="images/largeme.jpg">
    <source media="(min-width: 465px)"
            srcset="images/medme.jpg">
    <img src="images/smallme.jpg"alt="hero profile">
</picture>

try this:

<picture>
    <source media="(min-width: 465px)"
            srcset="images/medme.jpg">
    <source media="(min-width: 1000px)"
            srcset="images/largeme.jpg">
    <img src="images/smallme.jpg"alt="hero profile">
</picture>
like image 161
Diego Fortes Avatar answered Sep 17 '22 16:09

Diego Fortes