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

What's wrong with my path to the image?

Hello, I'm trying to put the image (named "graphic.jpg" nested in img folder) as a background (of course I'm doing it in CSS file) for the div and when I'm selecting it, nothing happens:

div {
  height: 300px;
  background-image: url("img/graphic.jpg");
} 

However when I put the image like this, it is displaying normaly, so I'm typing the right path to the image:

<div>
      <img src="img/graphic.jpg" alt="Graphic design">
    </div>

Try [CTRL] + [F5] to hard refresh the page within the browser. Maybe it's just a caching problem.

2 Answers

Try [CTRL] + [F5] to hard refresh the page within the browser. Maybe it's just a caching problem.

Hello @Bartłomiej Wilczyński, I believe the background-image elements URL attribute uses a relative path so unless your img folder is inside the same folder as your CSS file this may not work. You will need to add a '/ ' to the path of your folder it is in the root for example:

background-image: url("/img/graphic.jpg");

I'm not sure if this is the problem you are having but its worth a try.