Tuesday, 15 April 2014

html - Adding background image in Rails 4 -



html - Adding background image in Rails 4 -

how include background image in rails 4? trying add together onto div have in html. currently, image in /assets/images directory.

html:

<header> <div class="background_image"> </div> </header>

css:

.background_image { background: url(/assets/header-bg.jpg); }

with code have, no images beingness displayed

firstly, need add together css file scss extension, main.css.scss.

with can utilize asset helpers, like:

.background_image { background: image-url('header-bg.jpg'); }

as stated in docs, image-url("header-bg.jpg") becomes "url(/assets/header-bg.jpg)".

your markup empty (div.background_image) you'll need add together height style create work.

<header> <div class="background_image"> <!-- no content --> <!-- add together content or specify height --> </div> </header>

note: create of work, must utilize sass-rails gem (it's default in rails 4).

html css ruby-on-rails

No comments:

Post a Comment