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 trialMatthew Keys
1,922 PointsExplanation of the slash after the image position
Can someone please explain to me why you need to put a slash after the image position (center / cover)?
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Matthew,
This is a syntax requirement to remove ambiguity that would occur without it.
background-position
and background-size
can both accept some of the same types of values. For example, percentages and lengths.
Imagine the following background shorthand was used:
background: 30% 80%;
This can be interpreted multiple ways if we didn't have that forward slash syntax requirement. Are both of those values for the background-position? Are both for background-size? Is one for background-position and the other for background-size?
To remove this uncertainty, it was decided that background-position would be first, then a forward slash, and then the background-size.
This syntax also means that it's not possible to specify the background-size without also first specifying the background-position using the shorthand.
Going back to the earlier example, because the browser does not see a forward slash followed by values for background-size, it knows that the 30% 80% is for background-position. There is no other way to interpret it.