gpt4 book ai didi

css - 使 CSS url() 相对于文档

转载 作者:技术小花猫 更新时间:2023-10-29 11:36:11 25 4
gpt4 key购买 nike

当谈到 CSS 时,以下规则适用:

Partial URLs are interpreted relative to the source of the style sheet,
not relative to the document.

但这是我的问题:

我有不同的网站使用相同的 CSS 文件。虽然它们使用相同的布局,但 CSS 引用的实际图像对于它们中的每一个都是不同的。

例子:

#header {
width: 960px;
height: 200px;
background: url(/images/header.png);
}

每个域都有自己的“图像”文件夹和我希望 CSS 引用的“header.png”。目前它的行为符合预期,并尝试在托管 CSS 的域中找到 png 文件。我想要的是从调用 CSS 文件的域中获取 png 文件。

我对样式表使用“链接”,因为“@import”会破坏 IE 中的渐进式呈现。

有什么建议或解决方法吗?

最佳答案

What I want is for it to get the png file from the domain where the CSS file was called.

您必须为引用的每个域设置单独的 URL。所以 www.example1.com 将其样式表引用为 /style/sheet.css 并因此从 http://www.example1.com/style/中获取它sheet.csswww.example2.comhttp://www.example2.com/style/sheet.css 获取。

然而,仅仅因为它们看起来与客户端不同并不意味着它们在服务器端必须是不同的文件(以及所有这意味着的维护)。您可以将每个域上的 Alias 指向真实的共享 CSS 文件。

我能想到的唯一其他解决方法是拆分出 URL 引用规则,如 background-image 并将它们放在特定于域的样式表或内部样式表中。

关于css - 使 CSS url() 相对于文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1734688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com