Reputation: 1840
When opening a file from your hard drive into your browser, where is the document root? To illustrate, given the following HTML code, if the page is opened from the local machine (file:///)
then where should the css
file be for the browser to find it?
<link href="/temp/test.css" rel="stylesheet" type="text/css" />
Upvotes: 10
Views: 13739
Reputation: 22984
If you're interested in setting the document root, you might look at getting a web server installed on your machine, or, if you already have one (like Apache or IIS), storing your project-in-development in the web root of that server (htdocs in Apache, not entirely sure in IIS). If you'd rather leave your files where they are, you can set up virtual hosts and even map them to addresses that you can type into your browser (for example, I have a local.mrwarshaw.com address that resolves to the web root of my personal site's development folder).
If you're on Windows and don't want to mess around with setting up a server on your own, you could get a package like XAMPP or WAMPP, though bear in mind that those carry the extra weight of PHP and MySQL with them. Still, if you've got the space, they're a pretty easy drop-in development environment for your machine.
Upvotes: 0
Reputation: 250
It depends on what browser you use, but Internet Explorer, for example, would take you to the root directory of your harddrive (eg. C:/
), while browsers such as Firefox does nothing.
Upvotes: 2
Reputation: 1459
As far as local, static html goes, unless you specify it, most browsers will take the location of the html file you are viewing as the root. So any css put in there can just be referenced by it's name only.
The lazy way to get the correct reference for your css file is to open it in your browser. Then just grab the url that you see there - something like:
file:///blah/test.cssand copy that into your stylesheet link on your html:
<link href="file:///blah/test.css" rel="stylesheet" type="text/css">
Either that or you can just take the url for the html file and amend it to refer to the stylesheet.
Then your local page should load fine with the local stylesheet.
Upvotes: 0
Reputation: 531
You can, but probably don't want to, set the document root on a per-file basis in the head of your file:
<base href="my-root">
Upvotes: 16
Reputation:
On a Mac, the document root is what you see in the window that appears after you double click on the main hard drive icon on your desktop. The temp folder needs to be in there for a browser to find the CSS file as you have it written in your code.
Actually, you could also write the code like this:
<link href="file:///temp/test.css" rel="stylesheet" type="text/css" />
Upvotes: 1
Reputation: 4617
Eric, the document root is the folder in which your file is, wherever it may be.
Upvotes: 0