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

I can't seem to get the correct file path to link to an image from css. I'm using sublime text 2.

I am trying to set a background image for my jumbotron class, but my file path isn't working.

The folder I'm linking to is titled "images".

I've tried the following :
background-image: url('../images/interstellar.jpg'), ('images/interstellar.jpg'), and ('desktop/images/interstellar.jpg')

Could you show us how you organized you files?

1 Answer

Where is your images folder in relation to the css file? For example, is it something like:

/project
    /images /* i.e. images is on the same level as the css file
    styles.css
    index.html

/* OR */
/project
    /css
       styles.css
    images /* i.e. images one level above the css file
    index.html

/* OR something different perhaps? */

I haven't put my images folder or my css document within a project folder, is that the problem? I've tried compiling my CSS, images, and HTML files into one folder, but I cant seem to do so. Perhaps it's because I haven't paid for sublime text yet?

Please excuse my ignorance haha.

http://imgur.com/5YMla0N

When I said 'project' I meant generically, as in the main folder where all the files you're working on reside. :)

From the image I am assuming all the files, including images folder, are within shawn_website? i.e. so it looks like:

/shawn_website
    /images
    shawn.css
    shawnAbout.html
    shawnContact.html
    shawnServices.html

If this is the case then background-image: url('images/interstellar.jpg'); should work provided the image exists and the class or id the statement is within matches the same class or id of an HTML element.

Okay, now I understand that all of the files for the website i'm working on need to be within one project folder.

However, I'm unable to locate those files on my computer. The only way I can access them is by opening sublime text, clicking 'file', and 'open recent'.

All of my sublime text files currently reside in a 'user' file: http://imgur.com/3UuzQI4

The only way I can access them is by opening sublime text, clicking 'file', and 'open recent'.

When you click 'File' and hover over 'Recent Files' it will show you the path to the file(s).

ProTip: Use 'File' -> 'Open Folder' once you know the path to the folder you want to work with so you have all the files within that folder handy. Dragging a file or folder into the Sublime Text window works too which is really handy.

Okay so last question, what file path do i put for this ~/desktop/images/interstellar.jpg ? url('desktop/images/interstellar.jpg')?

Thanks, you've been a huge help.

I'm not sure we've determined where the images folder is exactly. You're saying ~/desktop/images/interstellar.jpg is where the image is? If so I would move it (the folder with the images) into the folder where the html files (and hopefully it's the same place as the css, too) are.

No worries; my pleasure. :)

url('desktop/images/interstellar.jpg') probably wouldn't work because the path is relative to the css file. As an example, you would use ../images/interstellar to point to a folder one level up from the css file -- ../ means go up one level (folder). It's not smart and doesn't know where desktop is without help.

Yeah I see what you're saying, but I can't find the folder where all of my html and css files are. I think that is where this whole issue is stemming from.

It's as if they don't exist on my computer. The only way I can find the files is by first opening sublime text.

When a file is open in Sublime Text you should see the path in the titlebar of the window (it does on Linux and Windows). If not click 'File' then 'Recent Files' but don't click a file. It should list all the recent files you've opened with the full path shown. Another way is if you open a file and click 'File' -> 'Save As', the 'Save As' dialog should display the folder where the file exists.

FOUND IT! It was under: ~/library/application support/sublime text 2/packages/user