我想要一个包含一组新 html 文件的新文件夹。它里面的所有图像都是格式src="image.png"
并且image.png
位于根文件夹中。但是,当您将 HTML 文件放在新文件夹中时,它找不到图像。你必须有它的格式src="../root folder/folder/image.png"
才能使它工作。这意味着很多粘贴。我试过把image.png
文件夹放进去,但没有改变。
问问题
24841 次
2 回答
22
使用<base>
元素。它允许您为页面中的所有相对 URL 指定 URL。
例如
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>This is an example for the <base> element</title>
<base href="http://www.example.com/news/index.html">
</head>
<body>
<p>Visit the <a href="archives.html">archives</a>.</p>
</body>
</html>
本示例中的链接将是指向“ http://www.example.com/news/archives.html ”的链接。
对您而言,基本 URL 可能像<base href="http://www.yoursite.com/">
. 这将使图像指定为src="image.png"
解析为"http://www.yoursite.com/image.png"
另请参阅https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
于 2013-06-28T19:03:49.403 回答
4
您需要设置base
标签。如果您<head>
像这样在页面中添加标签:
<base href="http://yoursite.tld/folder/">
它应该显示图像和相对于这个基本路径的源。
于 2013-06-28T19:01:21.413 回答