问题描述
我手动添加assets / images目录在rails 3.2应用程序,并添加了图像background.png。当引用来自css的图片
I manually added assets/images directory in a rails 3.2 app and added the image background.png . When referring to the image from css
background:url(assets / background.png)no-repeat;
我得到一个404,但是资产/样式表和资产/ javascripts正在显示。
I am getting a 404 , however assets/stylesheets and assets/javascripts are showing up.
* UPDATE
它似乎恢复为显式调用样式表ie
it appears as if I revert back to explicitly calling the stylesheet ie
<%=stylesheet_link_tag "home.css"%>
而不是
<%=stylesheet_link_tag "application" %>
背景图片重新正确
推荐答案
该url是相对于样式表的位置。您可能希望 url(../ assets / background.png)
从样式表或 url(/ assets / background .png)
从根开始。
That url is relative to where the style sheet is. You probably want either url(../assets/background.png)
to go up a level from your style sheet or url(/assets/background.png)
to go from the root.
这篇关于在CSS中使用rails 3.2显示背景图像时使用404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!