Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.