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

SeHyun Choi
SeHyun Choi
3,441 Points

How to make background-image responsive

I tried

background-image:url(" "); background-size:cover; background-repeat:no-repeat;

But when the screen gets to certain size (small) it doesn't show all the image. How do I fix that?

3 Answers

Steven Parker
Steven Parker
231,261 Points

It's normal for "cover" to trim off parts of the image to maintain the aspect ratio.

You could use "contain" instead of "cover" to insure the whole image is displayed, but then either the image will repeat or you get blank areas on the sides or top and bottom (known as "letterboxing").

The alternatives to these would distort the aspect ratio, which is generally even less desirable.

SeHyun Choi
SeHyun Choi
3,441 Points

Thank you everyone for your help.