I\'m writing a template for dreamweaver, and don\'t want to change the scripts for subfolder pages.
Is there a way to make the path relative to the root directory?
Just start it with a slash? This means root. As long as you're testing on a web server (e.g. localhost) and not a file system (e.g. C:) then that should be all you need to do.
/
means the root of the current drive;
./
means the current directory;
../
means the parent of the current directory.
use two periods before / , example: "../style.css"
To be relative to the root directory, just start the URI with a /
<link type="text/css" rel="stylesheet" href="/style.css" />
<script src="/script.js" type="text/javascript"></script>
I recommend using the HTML <base> element:
<head>
<base href="http://www.example.com/default/">
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
In this example, the stylesheet is located in http://www.example.com/default/style.css
, the script in http://www.example.com/default/script.js
. The advantage of <base>
over /
is that it is more flexible. Your whole website can be located in a subdirectory of a domain, and you can easily alter the default directory of your website.
This is oddly confusing to me. I know it shouldn't be. To check my understanding, I'd like to use a family relations model to compare. Assuming "You" is the current webpage, is the following correct?
<img src="picture.jpg"> In your folder with you, like a sibling
<img src="images/picture.jpg"> In your child's folder, under you
<img src="../picture.jpg"> In your parent's folder, above you
<img src="/images/picture.jpg"> In your cousin's folder
So, up to parent, over to sibling, down to their child = your cousin, named "images".