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
Salmen Bejaoui
8,017 Pointsimg 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
243,656 PointsThe "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.
Jaspal Singh
13,525 PointsHi
try to use the background-size property instead of size
Steven Parker
243,656 PointsThat will also not affect the size of the element itself.
Jaspal Singh
13,525 Pointsyes Steven your right its all about the width of an element after that the img will automatically get that size
Salmen Bejaoui
8,017 PointsSalmen Bejaoui
8,017 PointsThe problem here is the HTML5 Validator asking the sizes attribute.
Steven Parker
243,656 PointsSteven Parker
243,656 PointsIs this for a course where you could share a link to the page?