我想要一个包含一组新 html 文件的新文件夹。其中的所有图像均采用 src="image.png"
格式,image.png
位于根文件夹中。但是,当您将 HTML 文件放入新文件夹时,它找不到图像。您必须采用 src="../root folder/folder/image.png"
格式才能使其正常工作。这将意味着大量的粘贴。我尝试将 image.png
放入文件夹中,但没有任何变化。
最佳答案
使用 <base>
element.它允许您为页面中的所有相对 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
关于html - 在站点根文件夹中的文件夹中定义 HTML 的根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371785/