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

Alternative Method To Background Size Valid?

Is it possible to set the background-size to 100% and move on, or would that cause any issues further down the road?

background-image: url('../img/mountains.jpg'); background-size: 100%; background-repeat:no-repeat; background-position: center;

1 Answer

Steven Parker
Steven Parker
243,318 Points

What is it you are trying to achieve? Do you care if the image is clipped or stretched?

I find that I most often use "background-size: cover;" as it makes sure the entire element is covered, and clips the image as needed to preserve the aspect ratio. It also eliminates the need to specify "background-repeat".