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 trialIsaac Asante
4,752 PointsDifference between links with forward slashes and relative links.
Hi, I'm studying how to insert images into the website we're creating, through the img folder. I understand that these image files' paths (twitter-wrap.png, numbers-12.png, etc) are relative to the index.html file... But what if we were to create children pages, or new html pages which are not in the same directory as our img folder. Would we need to insert the same twitter-wrap.png or numbers-01.jpg images by placing a slash symbol before the img folder in the source link?
The question I am asking is... If I start image links with /, for instance: <img src="/img/twitter-wrap.png" alt="">, does this look for the img folder in the ROOT directory of the site, regardless of the html page on which the path is written?
What's the difference between writing src="/img/imagename" and src="img/imagename"?
Thanks, Ike
1 Answer
Ben Falk
3,167 Pointssrc="/img/imagename" : This would look at the root of the site's hosting, then find an img folder, then for the file itself.
src="../img/imagename" : This would start in the same folder as the current HTML file, then go "back" one folder into the parent folder, then look for a img folder, then for the file itself.
src="img/imagename" : This would start in the same folder as the current HTML file, then in the img folder, then for the file itself.
Hope that makes sense?
Isaac Asante
4,752 PointsIsaac Asante
4,752 PointsWow, I didn't know about the double dots (in your second example). Thanks for this insight!