I have an image in the assets/images
and I want to set it as a background on the main page refers to a given class, but I do not see image
in production Heroku
application.scss
.has-bg-img { background: url('img.PNG'); center center; background-size:cover; }
您必须设置完整的路径,例如url('localhost/apps/assets/images/myimg.jpg
')
如果您的资产不是静态的并提交到您的仓库中,并且您正在尝试引用动态上传的图像,则可能必须阅读如何使用Heroku的临时文件系统的信息。
You can try image-url
or asset-url
helpers.
Asset Pipeline
Edit : actually, i'm not sure about your syntax
.has-bg-img {
background-image: url('img.PNG');
background-position: center center;
background-size:cover;
}
it should work better.
In my Rails app, I change the filename to end with .scss.erb
and then have the following as an example. A comment at the top, followed by the example.
//= depend_on_asset "sprite-article-r4.svg"
.contents {
background-image:url('<%= asset_path("sprite-article-r5.svg") %>');
}
Reference this SO question
In Rails, you have to prepend directory name to url. For your case change
.has-bg-img { background: url('img.PNG'); center center; background-size:cover; }
to
.has-bg-img { background: image-url('img.PNG'); center center; background-size:cover; }
This is because you are storing your image in images(assets/images) directory.
Try to the following
.has-bg-img {
background-image: asset-url('img.png');
background-size: cover;
}
This should work, I don't why you use center center;
I think that is syntactically invalid see this Horizontal & Vertical Align
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.