资源管道要求和CSS中的相对图像路径
我有一些与 css 和图像捆绑在一起的 js 库。
在 asset/stylesheets/awesome-library/awesome-library.css 中,
background-image: url("some-image.png")
如果我们在布局中编写这样的内容,我们会看到类似的内容:
<%= stylesheet_link_tag "awesome-library/awesome-library" %>
浏览器将获取 http://example.org/assets/awesome-library/some-image.png
但是如果我们需要在我们的application.css:
//= require awesome-library/awesome-library
浏览器将获取 http://example.org/assets/some-image。 png (当然是404)
我尝试将awesome-library.css重写为scss(使用image-url),但结果是CSS url像/assets/some-image.png
。 我不想合并库的图像和所有其他图像,而且实际上也不想更改库的代码。
I have some js library bundled with css and images.
in assets/stylesheets/awesome-library/awesome-library.css we see something like
background-image: url("some-image.png")
if we'll write in our layout this:
<%= stylesheet_link_tag "awesome-library/awesome-library" %>
Browser will fetch http://example.org/assets/awesome-library/some-image.png
But if we'll require awesome-library/awesome-library in our application.css:
//= require awesome-library/awesome-library
Browser will fetch http://example.org/assets/some-image.png (404 of course)
I tried to rewrite awesome-library.css to scss (using image-url), but in result css url like /assets/some-image.png
.
I do not want to merge library's images and all other images and, really, do not want to change library's code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在 application.css 中使用
@import "awesome-library/awesome-library.css";
Just use
@import "awesome-library/awesome-library.css";
in your application.css