【问题标题】:Is there a way to prefix the url of an image referenced in .scss in case of CDN usage? [duplicate]在使用 CDN 的情况下,有没有办法为 .scss 中引用的图像的 url 添加前缀? [复制]
【发布时间】:2012-09-16 23:55:27
【问题描述】:

目前在我的.scss 文件中

.grid_pic {
    width : $width-grid;
    background : transparent url('/img/exemple_bg.png') 0 0 repeat;
}

有没有办法删除/img/ 并定义一个变量,或者一个配置文件,告诉所有图像的前缀是我想要的值?

所以在我们决定通过 CDN 提供图片的那一天,我们只需将 1 行配置从 /img/ 更改为 http://cdn.example.com/,而不是更改所有图片的 Url?

您将如何实现这一目标? (一个变量还是已经有一个配置?)

谢谢。

【问题讨论】:

    标签: css sass compass-sass


    【解决方案1】:

    您尝试过使用 image-url 功能吗?

    http://compass-style.org/reference/compass/helpers/urls/#image-url

    【讨论】:

      【解决方案2】:

      试试interpolation 语法和一个变量:

      background: url(#{$path_variable_name}/site/background.jpg);
      

      【讨论】:

        猜你喜欢
        • 2018-11-10
        • 2020-05-26
        • 2019-01-14
        • 2019-12-30
        • 2018-07-22
        • 1970-01-01
        • 2022-10-19
        • 2021-09-24
        • 1970-01-01
        相关资源
        最近更新 更多