@anasasiakiri4enko

Как подключаются img url backgroung через css?

Подскажите, как подключить путь к image через css в файле вьюхи? Как ни пробывал, не видит он у меня через CSS. А через Img всё ок.
  • Вопрос задан
  • 229 просмотров
Решения вопроса 1
@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");
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы