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 trialJohn Levy
1,451 PointsHow to link files in a different folder
Right now all my files are in the same folder. If I want to organize my files into several folders how do I go about linking them? I see a lot of sites explaining how to do this but I get confused when they use terms like main folder or secondary folder. Right now the folder that I have all my files in is called "Tunnel Vision Fitness" Within this folder I made another folder called "ebookdescriptions" where plan to keep all my files for this page such as the file "advancedmensdescription.html" and "advancedmensdescription.css" So using these descriptions how do I link the page advancedmensdescription.css and advancedmensdescription.html that are in the folder "ebookdescriptions" to the other docs that are all in the folder "Tunnel Vision Fitness" Sorry if I made it a little confusing I was just get confused with explanations such as main folder and secondary folder. Thanks in advance
5 Answers
Jason Anders
Treehouse Moderator 145,860 PointsIt's actually more simple than what it seems those sites you looked at made it out to be, and I have to admit, I haven't heard the terms "Main" folder ... "Secondary" folder used often in programming. The "Main" folder would be the Root
Folder. In your example this would be your "Tunnel Vision Fitness" folder. It is the Root
folder where every browser will look for the index.html (or index.php) file.
If you have many files / pages / stylesheets / scripts / ect. and you want to keep a neat File Tree, all other files would be in folders inside of the Root
folder. So, you could have a CSS folder for all the CSS files. A JavaScript folder for all your scripts. Or, in your example, a page folder with the files for that page. Let's call these "page1.css" and "page1.html" (to save me typing ).
To access, think of it just like you would say it... "Page1.css is in Page1's folder which is in TunnelVisionFitness' folder, so the access would look like TunnelVisionFitness/Page1/Page1.css
.
I hope this helps :)
Keep in mind, however, that as you move through the course, the organizational structure of the File Tree will become much more apparent as the the complexity of the instruction and pages increase. So, the how (and why) is coming.
Keep Coding! :)
Ethan Rivas
9,979 PointsOk, i'm not 100% sure if this is the answer for your question but I'll try :p.
Let's start from the basics, we have a project folder with:
- style.css
- javascript.js
- index.html
1) To link them you have to use the link tag and the script src attribute, inside your index.html insert:
-
For style.css (CSS Files)
<link rel="stylesheet" type="text/css" href="style.css">
-
For javascript.js (JS Files)
<script src="javascript.js"></script>
2) Now, if your style.css and javascript.js files are inside custom folders like:
- css
- style.css
- js
- javascript.js
index.html
-
For style.css (CSS Files)
<link rel="stylesheet" type="text/css" href="css/style.css">
-
For javascript.js (JS Files)
<script src="js/javascript.js"></script>
John Levy
1,451 PointsThanks for your feedback. Yes I also heard the term root folder several times when looking but I am still having trouble. Like I said all my files are in the folder "Tunnel Vision Fitness" and I plan to put the pages for one of my pages into the folder "ebookdescriptions" which is a folder I have within Tunnel Vision Fitness". Within the "ebookdescriptions" folder I plan to have the files "advancedmensdescription.html" and "advancedmensdescription.css"
To link the css file "advancedmensdescription.css I set it up like this- <link rel="stylesheet" href="TunnelVisionFitness/ebookdescriptions/advancedmensdescription.css"> This still does not link "advancedmensdescription.css" to the HTML file. What am I doing wrong?
Jason Anders
Treehouse Moderator 145,860 PointsIf your CSS file and HTML file are all in the same sub-folders, you shouldn't need to include all the sub-folders. Links in HTML files are relative (I believe... I work mostly on the Backend). So, to link the css file (in the same folder as the HTML file) should only require
<link rel="stylesheet" href="advancedmensdescription.css">
John Levy
1,451 PointsYes I tried this. I dont known if the issue is I have all the files in another folder. Right now I have a folder titled "coding" which I keep all my different css and html files for different projects in. The site I am working on now is in a folder within this called "Tunnel Vision Fitness". Up until now I have had all the files in the folder "Tunnel Vision Fitness" but now I want to organize them and have a separate folder called "ebookdescriptions" within the "Tunnel Vision Fitness" folder. Inside the "ebookdescriptions" folder I plan on having the files "advancedmensdescription.html" and "advancedmensdescription.css". The problem is once I take these two files out of the "Tunnel Vision Fitness" folder into the "ebookdescriptions" folder it is not linked anymore. I have tried the methods mentioned so far but still nothing is working.
John Levy
1,451 PointsYes this is what I wrote originally when I had the files in the folder "Tunnel Vision Fitness" When I made a new folder "ebookdescriptions" and placed "advancedmensdescription.html" and "advancedmensdescription.css" in it the page did not work. I tried <link rel="stylesheet" href="TunnelVisionFitness/ebookdescriptions/advancedmensdescription.css"> but that did not work either. I just cant see where I am going wrong.
Ethan Rivas
9,979 Points- What happen if you write this:
<link rel="stylesheet" href="/ebookdescriptions/advancedmensdescription.css">
- Or:
<link rel="stylesheet" href="../ebookdescriptions/advancedmensdescription.css">