我想从静态无 cookie 域提供我的 css 和图像。现在我的问题是如何从我的 css 文件中指向图像。
我不想在 css 文件中对我的域进行硬编程,例如:
我宁愿有一个指向图像的变量,所以它适用于我使用的每个静态域。
实现此目标的最佳方法是什么。我是否应该通过 php 运行整个 css 文件并在所有 png 引用前面添加静态域。缺点是我必须将整个 css 放在 html 中。
或者是否有另一种更优化的方法。
最佳答案
只要图像来自同一服务器的样式表,使用相对 URI 就足够了。
来自CSS Spec :
In order to create modular style sheets that are not dependent on the absolute location of a resource, authors may use relative URIs. Relative URIs (as defined in [RFC3986]) are resolved to full URIs using a base URI. RFC 3986, section 5, defines the normative algorithm for this process. For CSS style sheets, the base URI is that of the style sheet, not that of the source document.
Bert Bos(CSS 规范的作者之一)有一篇关于样式表中的变量的有趣文章。可以看一下here .
关于css - 从静态域提供 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2488369/