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

How do you write the background shorthand for background position, if the value is given in percent or pixels?

In CSS basics, the background shorthand is: color location repeat position size - ex: { background: #ffa949 url('../img/mountains.jpg') no-repeat center / cover }.

I was using 50% 50% for position, instead of center. How would you write this in shorthand?

{background: #ffa949 url('../img/mountains.jpg') no-repeat 50% 50% / cover;} ?

1 Answer

Hey Allison,

Here is the general format of setting the background shorthand property (from CSS Tricks):

body {
  background:
     url(sweettexture.jpg)    /* image */
     top center / 200px 200px /* position / size */
     no-repeat                /* repeat */
     fixed                    /* attachment */
     padding-box              /* origin */
     content-box              /* clip */
     red;                     /* color */
}

So, in your case it should be:

selector {
background: url('../img/mountains.jpg') 50% 50% / cover no-repeat #ffa949;
}

Ok, thanks.

You're welcome!