"Mozilla splash page" assessment

A post was merged into an existing topic: “Silly story generator” assessment

2 posts were merged into an existing topic: “Typesetting a community school home page” assessment

2 posts were merged into an existing topic: “Silly story generator” assessment

2 posts were merged into an existing topic: “Adding features to our bouncing balls demo” assessment

2 posts were merged into an existing topic: “Silly story generator” assessment

6 posts were merged into an existing topic: “Structuring planet data” assessment

2 posts were merged into an existing topic: “Fundamental CSS comprehension” assessment

Dear Mozilla,

First off, thank you for providing the excellent “Learn Web Development” tutorial and associated MDN resources. Phenomenal stuff.

I was wondering if you could provide some general feedback on my Mozilla-splash-page exercise. I noticed it doesn’t scale very well past < ~360px when inspected in responsive design mode (words / icons get truncated, go off screen) despite example solution picture being 321.5px and looking fine. Is that a default behavior or do I need to make some significant changes?

https://massproduced.github.io/mozilla-responsive/

Any input appreciated.

Kind Regards
Martin P.

Hi Martin,

Thanks for getting in touch. I’m so happy that you are enjoying the learning material :wink:

For the Splash Page example, your version looks really good, pretty much identical in output to our example! Well done.

the reason it starts to scroll horizontally and not look so great lower than 360px wide is that I have the CSS property min-width: 360px set on the body element. You’ve not done anything wrong.

If you remove that line from the styles.css file, it goes smaller without too much trouble, although the icon starts overlapping the heading.

Maybe I should remove that line from the exercise?

Hi Chris,

Thanks for the feedback. My thinking would be to leave the line in but make a note of that in the text. As in “Your result might be a little different, but don’t be alarmed, it’s b/c I’ve added the “min-width: 360px” line in my CSS for optimal viewing” kind of thing.

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

I’ve decided to just remove it from the exercise. I don’t think it should be explained at this stage, because I’ve not taught any CSS at this point in the course.

I am glad you got it sorted! The list bullets are missing because they have list-style: none set on them in the CSS.

Can someone explain to me the usage of this code?
https://pastebin.com/1KEE05BN

I am kind of confused. We are going to examine this piece of code:

<img> srcset=“mozilla-dinosaur-head_120.png 120w,
mozilla-dinosaur-head_400.png 400w”
sizes="(max-width: 480px) 120px,
400px"
src=“mozilla-dinosaur-head_400.png” alt=“A funny description”>


If the width of the viewport is 350px then the image width is going to be exact 120px, otherwise it should be 400px. But in my case something else is happening. When I resize the browser window, I am inspecting the image dimensions with the developer tools and the image shrinks as the browse window shrunks, ignoring the rules that define the exact dimensions of the image when a certain criteria is met. I have used Google Chrome and Mozilla Firefox. The code editor that I used is Brackets and I am using Live Preview.

This is a bit of a confusing situation, so let me try to explain.

The srcset attribute contains information on what images are available for use in this &lt;img&gt; element - it defines their filenames, and what their real width is (with the “w” unit).

The sizes attribute contains hints on what size slot the image will be expected to fill at a certain media condition. So here we are saying “when the viewport width is 480px or less, the expected slot size is 120px wide, otherwise the slot is more like 400px wide.” there is no exact sizing specified here - these are hints designed to allow the browser to make a sensible choice of what image file to load, based on the videwport size (or other media conditions, if specified).

So the effect this has is that if the viewport of your browser is 480px or less, the 120px wide image is loaded, but if not, the 400px image is used.

You can test it out; load this example: https://mdn.github.io/learning-area/html/multimedia-and-embedding/mdn-splash-page-finished/

Now open the browser dev tools, go to the Network tab, reload if necessary, then look at which dinosaur head image is downloaded. It should be the 400px one.

Now reduce your viewport width to really narrow, then do the same. You should now see that the 120px image is being loaded.

1 Like

The image still reduces in size when the viewport width is reduced, as shown on the screen , because it has max-width: 100% set on it in the CSS. This means that the image will always adjust its size to stay inside its parent element, as its width changes.

1 Like

This really happens. When I open the browser developer tools in Google Chrome and then I go to the Network Tab, I can see that the images that they are loading are the correct ones based on the width of the viewport. However, my worries is when I resize the viewport to let’s say 300px then the box model of the image element is not even close to 120w. Is that because of the max-width:100% ? Before the webpage was rendered I thought that the dimensions of the image would either be exact 120px or 400px.

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