HTML基本标记无法正常工作 [英] html base tag not working correctly
问题描述
这是我的文件夹结构。
- BaseWebsite(文件夹)
- - 根(文件夹)
- - default.html
- - css(文件夹)
- - js(Folder)
- - image(Folder)
指向 BaseWebsite
并使
这是我在 default.html中的代码
< ; HTML>
< head>
< link rel =stylesheettype =text / csshref =css / site.css/>
< script language =javascriptsrc =js / site.jstype =text / javascript>< / script>
< / head>
< body>
< img src =image / site.jpg/>
。
。
。
< / body>
< / html>
当我运行该页面时,css与 href =Root /css/site.css
但js和image缺少src文件从 js / site.js
和图片/site.jpg
所以我在< head>
< base href =/ Root //>
现在,js和image都显示出来,但css并没有显示,因为href变成 href =/ Root / Root / css / site.css
这是正常的还是我该如何解决?我可以通过将css的href改为 /Root/css/site.css
来解决它,但是有很多地方需要更改。
在 base
元素, href
属性必须是绝对URL,例如 http://www.example.com/foo/bar/
。以 /
(或。
)开头的网址是相对的。
您需要修复绝对URL或使用其他技术,例如服务器端编程工具或预处理器。
I am using html base tag in head but not working very well.
This is my folder structure.
- BaseWebsite (Folder)
- - Root (Folder)
- - default.html
- - css (Folder)
- - js (Folder)
- - image (Folder)
in IIS, i create a new web site pointing to BaseWebsite
and made Root
an application.
This is my code in default.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/site.css" />
<script language="javascript" src="js/site.js" type="text/javascript"></script>
</head>
<body>
<img src="image/site.jpg" />
.
.
.
</body>
</html>
When I run the page, css is there with the href="Root/css/site.css"
but js and image are missing with the src starting js/site.js
and image/site.jpg
So I put this after <head>
<base href="/Root/" />
Now, both js and image are showing but css is not showing as the href becomes href="/Root/Root/css/site.css"
Is it normal or how do I solve this? I can solve it by change href of css to /Root/css/site.css
but there are a lot of places to change.
In a base
element, the href
attribute must be an absolute URL, such as http://www.example.com/foo/bar/
. A URL that begins with /
(or .
) is relative.
You need to fix the absolute URL or use some other technique, such as a server-side programming tool or a preprocessor.
这篇关于HTML基本标记无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!