所以我正在开发我的新 Rails 应用程序,在我的一个样式表中我有 pg-parlex 类,它指定了一个背景图像链接:
.bg-parlex {
padding-top: 0px;
background-image: url('assets/banner-bg.gif'); /* << THIS URL LINK! */
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
谁能快速解释一下我们如何链接到 assets/images 文件夹中的元素...我确定它是 assets/item1.png
或 assets/item2.png
,但也许因为链接在样式表中,所以这可能是错误的...?
最佳答案
您可以使用:
background-image: image-url("rails.png")
#=> background-image: url(/assets/rails.png)
If you are using sass-rails gem:
background-image: asset-url("rails.png", image)
#=> background-image: url(/assets/rails.png)
因此,您的代码将是:
.bg-parlex {
...
background-image: asset-url("banner-bg.gif", image);
...
}
关于css - Rails 应用程序 - 在样式表中引用图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29320264/