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 How to Make a Website Styling Web Pages and Navigation Make a CSS Image Gallery

How to "Add CSS that will allow all images to fill their parent element." ?

I'm not sure what do here.

I used the selector img with a property max-width but not sure what value needs to be used.

img { max-width: ; }

Christopher Lebbano
Christopher Lebbano
15,338 Points

So max-width is just saying how wide it can possibly be. This is different than just "width", which says what the width should be. If you set the width property to 100%, it should be as wide as 100% of it's parent element.

1 Answer

Daniel Houghton
Daniel Houghton
4,334 Points

Hey there the max-width property can be used with % or px i.e. :

/* to give a max width of the picture which is equal to half the element, this is used to keep the ratio the same when the screen size is changed */

img { max-width: 50%; }

/* to give the max width of 20 pixels, this will lock the image to a maximum of 20 pixels "/

img { max-width: 20px; }

Thank you so much Daniel! I was able to resolve the issue and learned something along the way :)