css - 从静态域提供 CSS

标签 css static cookieless

我想从静态无 cookie 域提供我的 css 和图像。现在我的问题是如何从我的 css 文件中指向图像。

我不想在 css 文件中对我的域进行硬编程,例如:

http://static.com/image.png

我宁愿有一个指向图像的变量,所以它适用于我使用的每个静态域。

实现此目标的最佳方法是什么。我是否应该通过 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/

相关文章:

html - 在 hamburger bootstrap4 之前添加组件

c++ - 无法在Qt中调用静态方法

static - 我可以避免在没有 `static mut` 的情况下重新编译我的平台层吗?

python - 有没有办法在创建类(不是实例)时调用(静态)方法?

http - 这会保护我免受 Etag 跟踪吗?

javascript - 单击一个 div 将其展开并单击它以使用 javascript 将其关闭

html - 使用 Flexbox 创建适合内容的两列布局

css - 无法摆脱文本列之间的空白?

asp.net - 无 Cookie session 有多重要? Web 应用程序框架是否应该为它们提供支持?

Java (Tomcat) : how to configure a cookieless subdomain to serve static content