Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

1 Answer

Nikos Papapetrou
Nikos Papapetrou
6,304 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.