A
A
anasasiakiri4enko2016-05-22 00:36:19
Ruby on Rails
anasasiakiri4enko, 2016-05-22 00:36:19

How are img url backgroung connected via css?

Tell me how to connect the path to the image through css in the view file? No matter how I tried, he does not see me through CSS. And through Img everything is ok.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anasasiakiri4enko, 2016-05-22
@anasasiakiri4enko

You need to add your image to the app/assets/images folder and then you would use the <%= image_tag() %> on one of your templates.
This generates an image tag for use once in a file. However if you want a CSS background image the gem sass-rails is very helpful which you should already have in your Gemfile.
Create a new file called custom.css.scss in your app/assets/stylesheets folder and put in the following:
body { background-image: image-url("preston.jpg"); }
It should automatically generate the CSS (check it with your browser's inspector):
background-image: url("assets/preston.jpg");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question