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 Background Properties

position

Position the background image to be vertically and horizontally centered.

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Background Properties</title>
    <link rel="stylesheet" href="page.css">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="box"></div>
</body>
</html>
style.css
/* Complete the challenge by writing CSS below */
.box{
  background-color:#387ABC;
  background-image:url('img/mike.png');
  background-repeat:no-repeat;
  background-position:;


}

2 Answers

Chris Grazioli
Chris Grazioli
31,225 Points

Check out the reference material and learn how to help yourself better: https://developer.mozilla.org/en-US/docs/Web/CSS/background-position or http://www.w3schools.com/cssref/pr_background-position.asp

Just using background-position: center; should suffice, but center center; will work Try doing it with responsive percentages background-position: 50% 50%;

Gavin Ralston
Gavin Ralston
28,770 Points

So much for trying the no-nonsense reply! Thought I had a good feeling for the kind of rapport they wanted. :)

I repeat to myself, "Teach them to fish...."

Gavin Ralston
Gavin Ralston
28,770 Points
.box {
  background-position: center center;
}

first value is for horizontal center, second is for vertical :)