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 Responsive Images Image Delivery with Srcset and Sizes Adding Sizes

Eduardo Vargas
Eduardo Vargas
5,871 Points

What was the purpose of declaring "max-width: 50% in the CSS when 50VW is being declared in the sizes?

What was the purpose of declaring "max-width: 50% in the CSS when 50VW is being declared in the sizes?

2 Answers

Nikos Papapetrou
Nikos Papapetrou
6,305 Points

Percents are relative to the parent element. Assuming you have declared a div to be 80% width and inside the dive you set an image 50%. The 50% is subtract from the 80% percent of the parent element. So 50% is half of the 80% of the div. If you set the image 50vw the image will be relative to the with of the screen.

Timothy Mattingly
Timothy Mattingly
15,871 Points

The CSS setting is saying to place the image in a space that is half the size of its parent div, the wrapper. The 50% vw setting in sizes is telling the browser to find an image in srcset based on a pixel ratio that is half the viewport size.