image path in CSS - won't work???

776 views
Skip to first unread message

Bobo

unread,
Sep 30, 2008, 5:13:56 AM9/30/08
to Django users
Hi everyone,

I'm having a very strange problem with my Django project. I’ve a menu
with several links but I want to make a hover effect with it and for
that I use pictures.

The problem is that my path in my CSS won’t work and the pictures
aren’t loaded and therefore not shown in the menu.

My structure looks like this:

Djangoapps > myDjangoApp > urls.py
Djangoapps > myDjangoApp > skema > views.py

Djangotemplates > base.html (in here lie my menu section and it’s also
here I load the css file default.css)

Html > site_media > css > default.css
Html > site_media > img > a_hover.jpg
Html > site_media > img > menu.jpg

In my css file I have this code:
#menu {
width:100%;
padding-top:20px;
padding-bottom:20px;
background-color:#003399;
color:#FFFFFF;
text-align:center;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
font-variant:small-caps;
background-image: url('/site_media/img/menu.jpg');
}
#menu a {
color:#FFFFFF;
text-decoration:none;
padding:10px;
padding-top:20px;
padding-bottom:20px;
font-weight:bold;
}
#menu a:hover {
border-bottom:1px solid #ffffff;
border-left:1px solid #728d40;
border-right:1px solid #e9ffb7;
padding-left:9px;
padding-right:9px;
color:#000000;
background-color:#FFFFFF;
background-image:url(../img/menu.jpg);
font-weight:bold;

The problem here is the two lines:
background-image: url('/site_media/img/menu.jpg');
and
background-image:url(/site_media/img/menu.jpg);

I know they are different but that’s because I’ve tried so many
different combinations, like /site_media/img/menu.jpg but also ../img/
menu.jpg and so forth.

I’m simply run out of ideas but hopefully you can give me an answer on
what the heg it’s wrong.
I should say that the base.html correctly load the css file in and all
other css classes are correct and applied to the tables and div’s.

Thank you
- Emil

Kip Parker

unread,
Sep 30, 2008, 5:24:26 AM9/30/08
to Django users
A good start is to check you can view http://yoursite.com/site_media/img/menu.jpg
directly, if you get an error it will probably point you in the right
direction.

Erik Allik

unread,
Sep 30, 2008, 5:26:42 AM9/30/08
to django...@googlegroups.com
You should always use paths relative to the CSS file. Like this:
url(../img/menu.jpg)

Btw did you try going to that image file from the browser? If you're
using the built in development server, you need to set up static file
serving.

Erik
Reply all
Reply to author
Forward
0 new messages