Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

First Mobile approach images and breakpoints !!

OKAY guys so im currently working on a project website for a barbershop and im starting on a first mobile approach , what would be the best way to apply large pictures on larger screen and then when minimizing the window to mobile approach make the images TO NOT SHOW , i was thinking of the <picture> element but how would you properly use it on my html file ? thanks in advanced :)

I got a lot out of the "How to make a website" course. Try picking it up at the responsive web design section

2 Answers

Hey Eduardo, Your question taught me something today! So a cool solution for this could be to use the <picture> tag as you suggest, but do it a kinda funny way:

<picture>
  <source srcset="#" media="(max-width: 900px)">
  <img class="large-image" src="https://via.placeholder.com/1000x600">
</picture>

The reason is, Internet Explorer doesn't recognize the <picture> tag, so only that embedded <img> tag will be used in those browsers. So that's where you'd put your large image for larger screens. Then the <source> tag adds a media query that says if the screen width is 0-900px wide (you can change this to whatever size you want), replace the large image's src attribute with # -- in other words, don't show an image there. You'll get a broken link, which you can handle with CSS:

@media (max-width: 900px) {
    .large-image {
        display: none;
    }
}

The "old"/standard way of doing this would be to just use a media query to display: none; the image under a certain breakpoint. But I think this way is better because it doesn't actually download the image at all unless your screen is wide enough -- adding a performance boost.