Reputation: 6018
I'm trying to set a local site-root using the base tag. The following code isn't working. Am I doing something wrong? How do I set the mysite
folder as base?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="file:///home/me/mysite"></base>
<title> Asset Take On Process </title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/main.css" />
</head>
<body>
some stuff
</body>
</html>
The site folder structure is
mysite
|___css
|___img
|___js
and so on..
When I load the web-page it doesn't see the main.css
in the css
folder at all.
Upvotes: 9
Views: 24896
Reputation: 2237
Just to clarify the other answers:
The base tag must end in a slash. The following URL's must not begin with slashes:
It's logical, because adding them together makes a complete address. But it's counterintuitive because we're used to using /images/image.jpg to make things work everywhere.
Upvotes: 5
Reputation: 201528
A correct tag would be
<base href="file:///home/me/mysite/"/>
if you wish to set file:///home/me/mysite/
as the base address, so that e.g. css/main.css
refers to file:///home/me/mysite/css/main.css
. Note the importance of the slashes. In an href
value in base
, anything after the last slash is ignored: file:///home/me/mysite
means the same as file:///home/me/
there.
This is a confusing topic, and it is further confused by some browsers’ implementation that may support relative URLs in the value; by the specifications, only absolute URLs are permitted.
There is normally no reason to use the base
element. Relative URLs such as css/main.css
or ../css/main.css
work just fine, specifying addresses as relative to the address of the HTML page. This means that they need not be changed if the site is uploaded onto a server.
Upvotes: 7
Reputation: 8144
If you remove that /, it should make it relative off the current path, which, when a base tag is present would be
http://localhost/website/.
You will also need to add a trailing / to the end of the href, to indicate that it's a folder.
Full working example:
<!doctype html>
<html>
<head>
<base href="/test/" />
<script src="assets/test.js"></script>
<body>
hi
</body>
</html>
kindly refer this link
Upvotes: 6