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

Modure Rares
PLUS
Modure Rares
Courses Plus Student 9,041 Points

Why I cant use images in my code??

Whenever I want to use a image ( for example in the background-image propriety ) the image doesnt load.

nav-wrapper {

background-image: url('../cluj.jpg');
height: 300px;
width: 100%;

}

1 Answer

Michael Davis
PLUS
Michael Davis
Courses Plus Student 12,508 Points
nav-wrapper {
background-image: url('../cluj.jpg');
height: 300px;
width: 100%;
}

My first question, if we were pair-programming would be "Where is your image located in relation to this page?". For example, if this page is /mySite/assets/css/myStyles.css and the image you're referencing is in /mySite/assets/img/cluj.jpg, then you're pointer would need to be corrected since it would be pointing to /mySite/assets/.

If you're following along with the video, your images are in a folder called img and the CSS is in a folder called css if I'm not mistaking. If that's the case, then you need to:

background-image: url('../img/cluj.jpg');

This tells the browser to come out of the css folder, by 1 directory, and look for a folder called "img", then inside that folder, look for the image called "cluj".

Hopefully this helps!

EDIT Here's a bit more graphical explanation of traversing file structures.

Home location: //webroot/index.html
CSS location:  //webroot/css/myStyles.css
Image assets: // webroot/img/myImg.jpg

From within the CSS:
background-image: url('../img/myImg.jpg');

This tells the browser that, starting from //webroot/css/myStyles.css, go back by 1 directory which will bring it to //webroot/, then look for a folder called img and go into that directory. This will bring us to //webroot/img/, and finally look for the file myImg.jpg.