How can I use compass inline-image helper with an image url that is not relative?

空扰寡人 提交于 2019-12-11 22:22:40

问题


Problem

How can I use compass inline-image helper with an image url that is not relative?

config.rb

relative_assets = false

I also tried commenting that out completely

This code works

hdr-main.png lives in the /test/images/ on my local Server.

.test{
$image:"hdr-main.png";
background: inline-image($image);
}

This code does not work

.test{
$image:"http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/hdr-main.png";
background: inline-image($image);
}

Displays this error

Compass was unable to compile one or more files in the project:
File not found or cannot be read: /Users/myname/test/images/http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/hdr-main.png

回答1:


I'm not entirely sure what the issue is since you haven't actually asked a question. You have working code and I'm assuming you're trying to render a production stylesheet as well.

You should probably leave $image: "hdr-main.png" as-is then use config.rb to set your http_images_path to http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/.

You'll want to probably use this in conjunction with setting the environment to production.

if environment == :production
  http_images_path = "http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/"
end

then you'd build your CSS with the following

compass compile -e production

Again, this is assumption since there isn't a clear question posted above. If this isn't what you need, please ask a specific question.




回答2:


According to the Compass online documentation for inline-image :

the path specified should be relative to your project's images directory



来源:https://stackoverflow.com/questions/19405493/how-can-i-use-compass-inline-image-helper-with-an-image-url-that-is-not-relative

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!