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

CSS

img sizes="100%" ?

To have a valid HTML, if i use the srcset attribute, i have also to add the sizes attribute. I tried

<img sizes="100%">

but the percentage value is not valid. How can i set it to tell the browser that my image at any size must be 100% width of parent element ?

3 Answers

Steven Parker
Steven Parker
243,656 Points

The "sizes" attribute is used in combination with the "srcset" and has a different purpose. What you want to do would be accomplished with the "width" attribute instead.

The problem here is the HTML5 Validator asking the sizes attribute.

Steven Parker
Steven Parker
243,656 Points

Is this for a course where you could share a link to the page?

Hi

try to use the background-size property instead of size

Steven Parker
Steven Parker
243,656 Points

That will also not affect the size of the element itself.

yes Steven your right its all about the width of an element after that the img will automatically get that size