Help with responsive images. -Dill

Hello,

I am experimenting with responsive images and I am confused. I attempted to make two pages appear on website, one that uses art direction, and another that uses resolution switching. I wrote a simple HTML doc, and I ended up with a HTML doc that opens separate images, only one of which does any resolution switching at all. You can read the code and see for yourself. Would you be able to tell me where I went wrong? Thank you!

For all intents and purposes, you can assume that the images are in the same folder as the .html file. If need to upload the images, please let me know.

Thank you,

Aadil

I figured out one of my problems. Under the <picture> element, I put <img> instead of <source>.

Now i have two pictures. The first one, I cannot get to change art direction. The 2nd one does scale with the browser window.

Hi @ADillPickle :wave:

Two things to make it work:

  • The min-width and max-width values are missing px (e.g. (max-width: 799px) )
  • When using <img> with srcset the correct attribute is called sizes not media

Additionally, you can simplify your <picture> code by removing the second <source> element. If the viewport is wider than 799px it will automatically pick the default <img> (which is the same as your second <source> element)

I hope that helps! :slightly_smiling_face:
Michael

PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.

Thank you so much for the help. And thank you for the heads up about the “name” field. Autofill got me good.

1 Like

In your opinion, should I memorize the attributes and the elements? Or r should I just be aware of the tools? thank you!

1 Like

I don’t think that it’s necessary to actively remember these element/attribute combinations. In my opinion it’s enough to know that you can use multiple images with <img> and <picture>. For the details when you want to use it just look up the reference pages on MDN.

As they say:

You don’t have to know everything. You just have to know where to look it up.

After using them for some time you will eventually remember the attributes and won’t have to look it up every time. :slightly_smiling_face:

Good luck,
Michael

2 Likes