"Mozilla splash page" assessment

Yes, this is because of the max-width: 100% CSS.

  1. The srcset provides a hint to the browser as to what image would be most suitable to load based on the browser’s viewport width, device resolution, etc. Those “w” values are not exact image dimensions - they are hints as to the likely size of the image slot at different viewports.
  2. The browser then makes a choice and loads the chosen image.
  3. Once loaded, the image will be shown at it’s “true” size, unless some CSS comes into play and changes what the display size ends up being. In this case, max-width is making the images’ width be constrained to 100% of the width of their parent elements, so they are not shown at their true size.

Does that help?

1 Like

I did the panda image like this:

<picture>
                <source media="(max-width: 599px)" srcset="originals/red-panda-CloseShut.jpg">
                <source media="(min-width: 600px)" srcset="originals/red-panda.jpg">
                <img src="originals/red-panda.jpg" alt="panda">
            </picture>

But I see this one works ( copied from solution)

 <picture>
          <source media="(max-width: 600px)" srcset="red-panda-portrait-small.jpg">
          <img src="red-panda-landscape.jpg" alt="a red panda">
        </picture>

It seems the latter one is more efficient. Isn’t it?

1 Like

Yeah — in this case you don’t really need two <source> elements, as the image referenced in the <img src=""> is loaded by default if the media query test does not pass.

The smaller image is only loaded if the viewport width is 600px or less.

Hello!
just finished the Mosilla splash page Assessment, had fun doing it!
Please comment.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Mozilla splash page</title>
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
    <style>
      /* header and body setup */

      html {
        font-family: 'Open Sans', sans-serif;
        background: url(pattern.png);
      }

      body {
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
        background-color: white;
        position: relative;
      }

      /* Header styling */

      header {
        height: 150px;
      }

      header img {
        width: 100px;
        position: absolute;
        right: 32.5px;
        top: 32.5px;
      }

      h1 {
        font-size: 50px;
        line-height: 140px;
        margin: 0 0 0 32.5px;
      }

      /* main section and video styling */

      main {
        background: #ccc;
      }

      article {
        padding: 20px;
      }

      h2 {
        margin-top: 0;
      }

      p {
        line-height: 2;
      }

      iframe {
        float: left;
        margin: 0 20px 20px 0;
        max-width: 100%;
      }

      /* further info links */

      .further-info {
        clear: left;
        padding: 40px 0;
        background: #c13832;
        box-shadow: inset 0 3px 2px rgba(0,0,0,0.5),
                    inset 0 -3px 2px rgba(0,0,0,0.5);
      }

      .further-info a {
        width: 25%;
        display: block;
        float: left;
      }

      .further-info img {
        max-width: 100%;
      }

      .clearfix {
        clear: both;
      }

      /* Red panda image */

      .red-panda img {
        display: block;
        max-width: 100%;
      }
    </style>
  </head>
  <body>
    <header>
      <h1>Mozilla</h1>
      <!-- insert <img> element, link to the small
          version of the Firefox logo -->
        <img src="firefox-logo-120w.png" alt="firefox logo: a fox and the world">
    </header>

    <main>
      <article>
        <!-- insert iframe from youtube -->
        <iframe width="400" height="225" src="https://www.youtube.com/embed/ojcNcvb1olg" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
        <h2>Rocking the free web</h2>

        <p>Mozilla are a global community of technologists, thinkers, and builders, working together to keep the Internet alive and accessible, so people worldwide can be informed contributors and creators of the Web. We believe this act of human collaboration across an open platform is essential to individual growth and our collective future.</p>

        <p>Click on the images below to find more information about the cool stuff Mozilla does. <a href="https://www.flickr.com/photos/mathiasappel/21675551065/">Red panda picture</a> by Mathias Appel.</p>
      </article>

      <div class="further-info">
        <!-- insert images with srcsets and sizes -->
        <a href="https://www.mozilla.org/en-US/firefox/new/">
          <img srcset="firefox-logo-120w.png 120w, firefox-logo-400w.png 400w" sizes="(max-width:480px) 120px" src="firefox-logo-400w" alt="Firefox logo, a fox and the world">
        </a>
        <a href="https://www.mozilla.org/">
          <img srcset="mozilla-dinosaur-120w.png 120w, mozilla-dinosaur-400w.png 400w" sizes="(max-width:480px) 120px" src="mozilla-dinosaur-400w.png" alt="a red dinosaur, the mosilla one">
        </a>
        <a href="https://addons.mozilla.org/">
          <img srcset="firefox-addons-120w.jpg 120w, firefox-addons-400w.jpg 400w" sizes="(max-width:480px) 120px" src="firefox-addons-400w.jpg" alt="puzzle pieces forming the firefox logo">
        </a>
        <a href="https://developer.mozilla.org/en-US/">
          <img src="mdn.svg" alt="a geometric waving flag with a t-rex head vain in the center">
        </a>
        <div class="clearfix"></div>
      </div>

      <div class="red-panda">
        <!-- insert picture element -->
        <picture>
          <source media="(max-width:599px)" srcset="red-panda-croped-600w.jpg">
          <source media="(min-width:600px)" srcset="red-panda-1200w.jpg">
          <img src="red-panda-1200w.jpg" alt="a red panda chilling like money ain`t a thang">
        </picture>
      </div>

    </main>
  </body>
</html>

Hello again!

I have checked your work, and it looks pretty good. The main feedback I had was that the images don’t seem to load, but this is not a big deal — I’m assuming you just have your assets named differently to our example?

I’d also like to invite you to check your code against the marking guide, and our finished example:

Hi,

I have completed the Mozilla splash page problem.

Please review my solution.

Thank you,
Sharon

Hi there @sharon97 — I have looked at this, and it seems to do everything it is supposed to do. Well done on some great work! As I’ve said before, if you want to compare it to our version and review your code in more detail, look at the links I included in the previous replies.

Hi, I finished the “Mozilla Splash page” just fine, but I noticed I was having an error in my code. I noticed that even if you have the src attribute set for an img tag, if it fails to find the srcset files (as in a misspelling) it will ignore the src attribute and go straight to the alt attribute and display that. I’m thinking it might have something to do with the sizes attribute meta queries interfering with that. As in it satisfies one of the queries, tries to load the corresponding one and ignores whether or not that file can be found.

Hrm, that is quite interesting. I’d not seen this behavior. Have you got a test case published anywhere?

Hi, thanks for responding!

I couldn’t post the zip file of my project here directly so I put the link to a google drive to it below.

https://drive.google.com/file/d/1MNTbWEz0n6uHcWQSCvTVbJ0wmHd26DTu/view?usp=sharing

If you check my html file, you will notice the last image of the row (the dinosaur) is not displaying (this is at line 143-148) if you take out both the srcset and sizes attributes, it will display the src attribute file. However if you leave them in and have the srcset files misspelled (“mozilla-dinosaur_head_120w.png” instead of “mozilla-dinosaur-head_120w.png” note the second undescore should be a hyphen) it won’t display the src attribute file. Now of course if they are spelled correctly there is no problem, but I read that you should still set the src attribute just in case the srcset files don’t work.

Yeah, I’ve tried it and you are right. This is strange behavior — you’d totally expect it to show the src image as a fallback if it can’t find the srcset images, not the alt text (unless it can’t find the src image either).

It seems to do the same on Chrome and Firefox.

I’d be interested to see what our platform engineers have go to say about this. Can you file a bug about this on our https://bugzilla.mozilla.org/ site?

When the splash page is loaded, the Network tab in Developer mode shows that both firefox-logo120.png and firefox-logo400.png are be loaded instead of one.

Is this intentional?
If the viewport is high enough (higher than 480px in this case), shouldn’t only the firefox-logo400.png be loaded?

Hello again @Datalighter. Are you seeing this in Chrome’s devtools/responsive mode? There is a known issue there.

Hey @chrisdavidmills
Thank you for clarifying that. Yes, this is in Chrome’s devtools. Fortunately, I believe this known issue was actually noted later in the assessment page. I must’ve overlooked it.

Note : Be advised that when testing your assessment in the Chrome browser using the Developer Tools, the browser may not load the appropriate image no matter how small you set the width in the ‘reponsive view’. It seems to be a feature of Chrome. The Firefox browser should load the correct image (assuming your HTML is correct).”

I think we added that fairly recently, so you could easily have missed it.

I’m having trouble testing the responsiveness of the images, even with the finished example.

I’m using up-to-date Firefox.

With my browser window at full screen width, I go the network tab in the developer tools and load the finished example page. The network inspector lists firefox-logo400.png, mozilla-dinosaur400.png, and firefox-addons400.jpg. Then I use responsive view mode to set the width under 480 pixels (or just shrink my browser window as narrow as it will go when I drag the corner), reload the page, and see the same three files appear in the network tool.

If I understand correctly, I should be seeing firefox-logo120.png, etc., listed in the network inspector after reducing the width. (The panda photo works the way I expect: I see the smaller photo in the network inspector upon shrinking the browser.)

What am I missing?

hi @bmooney7984,

Sorry for the long delay in responding!

I just tried it in the latest Firefox, and it worked OK for me. I first resized my browser window to the narrowest width it’d go to, then opened devtools, then went to the network tab and reloaded the page.

At this point, I then saw the correct size assets loaded (120 x 90, not 400 x 300). The srcset images are listed in the network tab as “imgset” in the “Cause” column, not “img”, which makes them easier to spot.

Hi, I tried the Mozilla splash page assignment and published my solution on github. Please have a look.
https://tushar9604.github.io/multimedia-and-embedding.html

@tushar9604 I’ve looked over this one too — great work, this functions just as expected. Well done!

@chrisdavidmills thanks your feedback. I will be try to follow the tutorials on mdn further. So please continue your feedback and help.