Eduardo Álvarez
Eduardo Álvarez

Reputation: 353

Rails 5 how to access image in public folder from css file also in public folder

I have CSS file

public/stylesheets/landing.css

It works fine when using tag

<%= stylesheet_link_tag "/stylesheets/landing" %>

I also have this image

public/images/1-hero-image.jpg

Now, inside the css file I am trying to reference this image.

I have tried following variants:

background: url('1-hero-image.jpg');
background: url('/public/images/1-hero-image.jpg');
background: url('/images/1-hero-image.jpg');
background: url('images/1-hero-image.jpg');

None of them seems to work.

I will be grateful for any help you can provide.

Upvotes: 0

Views: 1276

Answers (1)

mechnicov
mechnicov

Reputation: 15288

background: url('/images/1-hero-image.jpg'); is enough in your situation.

But it's better to use for CSS and images folder app/assets/

Upvotes: 1

Related Questions