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 CSS Foundations Backgrounds and Borders Advanced Backgrounds

SAMUEL LAWRENCE
PLUS
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

What is the **contain** value useful for when using the background-size property?

Hi I'm unable to figure out when the contain value for the background-size property might be useful. It seems to clip the image allowing for white spaces. In today's modern browsers that resize it seems to be an outdated rule. Can someone help me understand? thanks.

mrx3
mrx3
8,742 Points

http://www.css3.info/preview/background-size/

Here's a good site with some good examples. Scroll down the page and read the cover and contain section. I'm horrible at explain things in my own words but I know how to use the declaration contain. I hope this helps out.

1 Answer

Naomi Freeman
STAFF
Naomi Freeman
Treehouse Guest Teacher

"The contain value specifies that regardless of the size of the containing box, the background image should be scaled so that each side is as large as possible while not exceeding the length of the corresponding side of the container."

http://codepen.io/summerspirit/pen/OPXrxm

This is in contrast to the cover value:

"The cover value specifies that the background image should be sized so that it is as small as possible while ensuring that both dimensions are greater than or equal to the corresponding size of the container."

http://codepen.io/summerspirit/pen/QwEzqQ

These can always be used in web apps, but many of the needs around this come from the new demands of mobile sizing.