【发布时间】:2015-09-13 08:42:04
【问题描述】:
我正在编写一个 Web 组件。因此,我有一个 index.html,我在其中导入了 Web 组件:
<link rel="import" href="components/test.html">
如您所见,我将组件放在相对于 index.html 的特定文件夹中。现在,当我想从组件文件夹中的 test.html 访问资源时。我想这样做:
background-image: url("test.gif");
对于 css 或:
<img src="test.gif">
但它不起作用。它仅在我将图像的相对路径更改为 index.html 时才有效,例如:
<img src="components/test.gif">
我知道你可以使用document.currentScript.baseURI 之类的技巧,但我想编写纯 CSS 和 HTML。有没有简单的方法?
【问题讨论】:
标签: html import path relative-path