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

back ground size

set the background size to 20px square?

1 Answer

Garrett Levine
Garrett Levine
20,305 Points

I am curious what your intention is. backgrounds are meant to (usually) encompass the entirety of the container they are placed in. So, for example, a background of a website will take up the entire page, whereas the background on an element will take up the entire element. Unless you actually are asking how to re-size an image, I'm going to proceed as if you were trying to set a background to a specific size for a specific element on the page.

the way I would do it is to make sure the container is 20px by 20px. In the CSS it would look like this;

container {
 height: 20px;
 width: 20px;
}

then I would make sure that the background is the correct size by using CSS to edit it like so;

 background-image {
 background: url (' ') no-repeat contain;
}

the above CSS will make the image scale down to the size of the container, without losing any quality.