当我通过相对路径引用CSS文件中的图片或其他文件时,是使用CSS文件相对于CSS文件还是HTML文件的路径?
当我通过相对路径引用CSS文件中的图片或其他文件时,是使用CSS文件相对于CSS文件还是HTML文件的路径?
Answers:
是的,这是相对于 .css
这是一个示例布局:
Page: page.htm ... does not matter where
CSS: /resources/css/styles.css
Image: /resources/images/image.jpg
CSS中styles.css
:
div { background-image: url('../images/image.jpg');
.css
文件,.html
而无需制动到外部对象的路径。
是。它相对于CSS文件。我还要补充一点,这也包括相对于CSS文件所在的域。
因此,如果CSS被引用为:
<link href="http://www.otherdomain.com/css/example.css" type="text/css" rel="stylesheet" />
它包含:
div { background-image: url('/images/image.jpg');
背景将是:
是的,它与样式表有关。有关最新参考,请参见MDN。目前,最新草案为[ css-values-4 ]。