Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify a Root Path of your HTML directory for script links?

Tags:

html

path

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?

for example:

<link type="text/css" rel="stylesheet" href="**root**/style.css" /> 

Instead of **root** above, I want a default path there. Is there any way to do anything like this?

like image 914
Gazow Avatar asked Apr 19 '11 07:04

Gazow


People also ask

How do I specify the root directory in html?

You have to have it in the format src="../root folder/folder/image.

How do I create a root directory in path?

To get the root directory of a path, you can use GetPathRoot() method from Path class that's contained in the namespace System.IO . This method returns to you the root directory from a path passed as string argument.


2 Answers

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> 
like image 84
Quentin Avatar answered Sep 24 '22 23:09

Quentin


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.

like image 35
Alexander Jank Avatar answered Sep 24 '22 23:09

Alexander Jank