# Background image defined in stylesheet doesn't display

**URL:** <https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610>\
**Category:** Ruby\
**Created:** [April 15, 2009, 6:22pm UTC](https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610 "2009-04-15T18:22:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e4f/32.png) [@rubio](https://www.ruby-forum.com/u/rubio)\
**Post date:** [April 15, 2009, 6:22pm UTC](https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610/1 "2009-04-15T18:22:34Z")

</div>

application.html.erb is correctly finding the stylesheet for my project  
via \<%= stylesheet\_link\_tag ‘style1’ %\>. My webpages reflect the  
styling properly with a few exceptions … the most notable being some  
.jpg images defined for background do not display at all. I have those  
images in public/images.

The following is the stylesheet code containing the reference to the  
image.

#navigation {  
width: 180px;  
height: 484px;  
background: #7da5a8 url(backgrounds/nav-bg.jpg) no-repeat;  
}

This worked fine until I retrofitted the webpages into the Rails  
framework (which I really like, but which I’m relative new to).

If anyone knows the solution, I would really appreciate it … thanks in  
advance!

Rubio

---

<div class="post-metadata">

**Author:** ![rubio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e4f/32.png) [@rubio](https://www.ruby-forum.com/u/rubio)\
**Post date:** [April 15, 2009, 6:32pm UTC](https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610/2 "2009-04-15T18:32:03Z")

</div>

Rob B. wrote:

> application.html.erb is correctly finding the stylesheet for my project  
> via \<%= stylesheet\_link\_tag ‘style1’ %\>. My webpages reflect the  
> styling properly with a few exceptions … the most notable being some  
> .jpg images defined for background do not display at all. I have those  
> images in public/images.

So, the URL for the images is images/… relative to the path of your  
application.

> The following is the stylesheet code containing the reference to the  
> image.
> 
> #navigation {  
> width: 180px;  
> height: 484px;  
> background: #7da5a8 url(backgrounds/nav-bg.jpg) no-repeat;  
> }  
> If your stylesheet is in public/stylesheets/styles.css [example], then  
> the relative path to the images directory is:  
> url(…/images/…jpg) or url(…/images/backgrounds/image.jpg)  
> depending on where exactly you placed the files.

Cheers,  
Mohit.  
4/16/2009 | 12:30 AM.

---

<div class="post-metadata">

**Author:** ![rubio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e4f/32.png) [@rubio](https://www.ruby-forum.com/u/rubio)\
**Post date:** [April 15, 2009, 6:44pm UTC](https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610/3 "2009-04-15T18:44:26Z")

</div>

Mohit S. wrote:  
If your stylesheet is in public/stylesheets/styles.css [example], then  
the relative path to the images directory is:  
url(…/images/…jpg) or url(…/images/backgrounds/image.jpg)  
depending on where exactly you placed the files.

> Rob B. wrote:
> 
> > application.html.erb is correctly finding the stylesheet for my project  
> > via \<%= stylesheet\_link\_tag ‘style1’ %\>. My webpages reflect the  
> > styling properly with a few exceptions … the most notable being some  
> > .jpg images defined for background do not display at all. I have those  
> > images in public/images.
> 
> So, the URL for the images is images/… relative to the path of your  
> application.
> 
> > The following is the stylesheet code containing the reference to the  
> > image.
> > 
> > #navigation {  
> > width: 180px;  
> > height: 484px;  
> > background: #7da5a8 url(backgrounds/nav-bg.jpg) no-repeat;  
> > }  
> > If your stylesheet is in public/stylesheets/styles.css [example], then  
> > the relative path to the images directory is:  
> > url(…/images/…jpg) or url(…/images/backgrounds/image.jpg)  
> > depending on where exactly you placed the files.
> 
> Cheers,  
> Mohit.  
> 4/16/2009 | 12:30 AM.

Many thanks Mohit … worked beautifully using the relative path !!  
Didn’t expect such a quick response with the correct solution !!

Cheers to you as well !

---

<div class="post-metadata">

**Author:** ![rubio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e4f/32.png) [@rubio](https://www.ruby-forum.com/u/rubio)\
**Post date:** [April 15, 2009, 6:58pm UTC](https://www.ruby-forum.com/t/background-image-defined-in-stylesheet-doesnt-display/165610/4 "2009-04-15T18:58:28Z")

</div>

Rob B. wrote:

> Many thanks Mohit … worked beautifully using the relative path !!  
> Didn’t expect such a quick response with the correct solution !!
> 
> Cheers to you as well !

You’re most welcome. I’m not replying for you, it’s a selfish move - I  
just asked a question myself, so I’m waiting for answers 😛  
This is me paying it forward 🙂

Cheers,  
Mohit.  
4/16/2009 | 12:57 AM.
