Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-10-2010, 11:52 AM   PM User | #1
authorandrew
New Coder

 
Join Date: May 2010
Posts: 79
Thanks: 8
Thanked 0 Times in 0 Posts
authorandrew is an unknown quantity at this point
Subfolders in a web-design project

Hi everyone,
I've been coding for about eight months now in HTML, XHTML, etc, but the projects have always been small snippets which means that I've been able to keep everything in one folder with no subfolders. Now that I'm starting my first project...I find that I can't use subfolders.

The correct use of a subfolder would be like this:

Code:
<img src="/subfolder/image.jpg" />
Am I missing something or is this not the right way to do this...assuming that the subfolder is in the same folder as the HTML file. When I do this the image doesn't show up but if I put it in the main folder and adjust the code accordingly it shows up fine.

Thanks,
aa
authorandrew is offline   Reply With Quote
Old 06-10-2010, 12:01 PM   PM User | #2
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
<img src="/subfolder/image.jpg" />

I think the leading slash is not necessary.

Frank
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.
effpeetee is offline   Reply With Quote
Old 06-10-2010, 01:08 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Look into relative and absolute paths. If you’re developing locally (i. e. without server) then you should use relative paths.

Absolute path with specific domain:
Code:
<img src="http://example.com/subfolder/image.jpg" />
Domain independent absolute path (will look for the file from the root directory – in your case this looks for a subfolder in the top directory of the hard disk):
Code:
<img src="/subfolder/image.jpg" />
Relative paths, relative to current HTML document:

Looks for the file in a folder on the same level as the document:
Code:
<img src="subfolder/image.jpg" />
Looks for the file in a folder one level above the current document:
Code:
<img src="../subfolder/image.jpg" />
In CSS and HTML files you write the paths relative to the current file. In external JavaScript files you would write the paths relative to the document where the script is executed (i. e. relative to the file where the path is used).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 06-10-2010, 02:32 PM   PM User | #4
authorandrew
New Coder

 
Join Date: May 2010
Posts: 79
Thanks: 8
Thanked 0 Times in 0 Posts
authorandrew is an unknown quantity at this point
It worked after removing the leading slash. I'm not planning on putting this page on the web, but for the purposes of learning, let's assume that I were going to. Would I have to redo all of these paths as absolute url's, or the fact that they would be hosted in the same folder as index.html makes it all right as it is?

Thanks a lot,
aa
authorandrew is offline   Reply With Quote
Old 06-11-2010, 08:49 AM   PM User | #5
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Yeah, if the structure (i. e. the relation of the files to one another) stays the same then you don’t need to change anything.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 06-11-2010, 10:09 AM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Would I have to redo all of these paths as absolute url's, or the fact that they would be hosted in the same folder as index.html makes it all right as it is?
You may practice the things by installing a local server in your machine like xampp or wamp and you could use the absolute paths after setting up a virtual server there. ( Personally, I prefer absolute paths as it's very easy when dealing with complex directory structures or when making friendly urls)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 06-11-2010 at 10:11 AM..
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 PM.


Advertisement
Log in to turn off these ads.