【问题标题】:How can I use compass inline-image helper with an image url that is not relative?如何将 compass inline-image 助手与不相关的图像 url 一起使用?
【发布时间】:2014-10-17 07:50:12
【问题描述】:

问题

如何将指南针 inline-image helper 相对的图片网址一起使用?

config.rb

relative_assets = false

我也尝试过将其完全注释掉

此代码有效

hdr-main.png 位于我本地服务器上的 /test/images/ 中。

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

这段代码工作

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

显示此错误

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

【问题讨论】:

    标签: css compass-sass


    【解决方案1】:

    我不完全确定问题出在哪里,因为您实际上并没有问过问题。你有工作代码,我假设你也在尝试渲染一个生产样式表。

    您可能应该保留 $image: "hdr-main.png" 原样,然后使用 config.rb 将您的 http_images_path 设置为 http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/

    您可能希望将其与将 environment 设置为生产环境结合使用。

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

    然后您将使用以下内容构建您的 CSS

    compass compile -e production

    同样,这是假设,因为上面没有明确的问题。如果这不是您需要的,请提出具体问题。

    【讨论】:

    • 我应该从 config.rb 中删除 images_dir = "img" 吗?
    • 这不是问题,你只是不能内联远程图像(我认为)。如果你想内联它,只需在你的系统上使用它的本地路径。
    【解决方案2】:

    根据inline-image 的 Compass 在线文档:

    指定的路径应该相对于您项目的图像目录

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多