如何引用托管在不同域中的CSS资产中的图像位置? [英] How to reference image locations in css asset hosted on a different domain?

查看:32
本文介绍了如何引用托管在不同域中的CSS资产中的图像位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://www.link1.com 有一个网站,所有的php和图像都在该网站上,我想从不同的网站(如 http://www.link2.com (此网站不托管任何CSS图像)

I have a website at http://www.link1.com where all the php and images are, and I want to load the css from different website like http://www.link2.com (this doesn't host any of the css images)

我从css中获得了填充,边距和排列的东西,但没有图像.

I got the padding, margins, and arangement stuff from the css but not the images.

浏览器是否对此进行限制?跨域CSS加载有什么方法吗?

Do browsers restrict this? Is there any way for cross-domain css loading?

推荐答案

您可以将CSS托管在另一台主机上没有问题.如果填充等有效,则加载CSS.如果图像不起作用,请检查CSS中指定的路径.

You can host your css on another host no problem. If the paddings etc are working then the css is loaded. If images are not working, check the paths specified in your css.

编辑:如果图片托管在其他域中,则应在CSS定义中使用绝对网址,即:

Edit: You should use absolute urls in your css definitions if the images are hosted on a different domain, i.e:

background: url('http://link2.com/path/to/image.jpg');

因为相对路径是相对于CSS位置而不是父页面的相对路径(显然,对于IE而言,请参见下面的Rob回答).

as relative paths are relative to the css location, not the parent page (except, apparently for IE, see Rob's answer below).

这篇关于如何引用托管在不同域中的CSS资产中的图像位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆