Is there a way to prefix the url of an image referenced in .scss in case of CDN usage? [duplicate]

空扰寡人 提交于 2019-12-02 07:13:47

问题


Currently in my .scss file I have

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

Is there a way of removing the /img/ and to define a variable, OR a configuration files that tells to prefix all the images with the value I want ?

So the day we decide to serve our images via CDN, we just have to change 1 config line from /img/ to http://cdn.example.com/ instead of changing all the Url of the images ?

How would you achieve that ? (a variable or is there already a config for that ?)

Thanks.


回答1:


Try the interpolation syntax along with a variable:

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



回答2:


did you try with image-url function ?

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



来源:https://stackoverflow.com/questions/12583396/is-there-a-way-to-prefix-the-url-of-an-image-referenced-in-scss-in-case-of-cdn

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