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

Difference between max-width and width for images in responsive design?

What is the difference between setting the width of images to 100% and setting the max-width to 100%? Doesn't this do the same thing?

2 Answers

Hi Harry Troy.

max-width:


The max-width property in CSS is used to set the maximum width of a specified element. The max-width property overrides the width property, but min-width will always override max-width whether followed before or after width in your declaration.

Note that max-width and width should not be applied to the same element using the same unit, as one will override the other.

For further reading:

I not exactly sure, but I believe that the "max-width" is the biggest it can get, while the "width" is just setting the size in comparison with the patent element. But again I could be wrong so you can try googling it and maybe you'll find a better answer.