Setting background-image in CSS file for ASP.NET application

Hello,

I'm trying to set a background image for one of my pages using css file and for some reason it doesn't work :(

I can do it directly through the body tag:
style="background-image:url('Images/bgdesert.jpg')"

I can do it in the inner css in the header section:
    <style type="text/css">
            body
            {
                  background-image: url('Images/bgdesert.jpg');
            }
      </style>

But when I add it to the css file, it doesn't work :(
body
{
      background-image: url('Images/bgdesert.jpg');
}

Everything else in this section (I have other elements, just didn't show them) works fine, but not background-image. Any idea why?

Thanks
LVL 21
YurichAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GuitarRichConnect With a Mentor Commented:
is the css file in the same folder as the aspx page? the url works relative to the path the css file is in so make sure that path is correct. e.g if the css is in a folder called styles you would change it too:
body
{
      background-image: url('../Images/bgdesert.jpg');
}
0
 
YurichAuthor Commented:
you're right, css file in App_Themes/App_Theme/

so it should be      background-image: url('../../Images/bgdesert.jpg');
but still not working, I actually tried ../ and ../../ both, still no good...
0
 
GuitarRichCommented:
or put your image in the app_theme folder and do background-image: url('bgdesert.jpg');
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
YurichAuthor Commented:
doesn't work :(

can you try to create a very simpl project and see if it's going to work - just one page and one image and refer to it from a css file?

Thanks
0
 
qwerty021600Commented:
does the image need to be repeated.. i mean in either x or y coordinates?
0
 
qwerty021600Commented:
check for the path.. if you giving the right path. also give height and width of the image.
0
 
tetorvikConnect With a Mentor Commented:
Are you sure you don't have any inline CSS blocks or style attributes on body tag that overrides the css in the linked css file (inline css will override the linked css if both declared)?
0
 
GuitarRichCommented:
just created one and it worked ok. Just one thing - have you setup the theme in the webpage? You need to either add it to the web.config or you can put it at the top of the page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Theme="Theme1" Inherits="_Default" %>
 
0
 
YurichAuthor Commented:
OK, thank you guys, found a problem.

There was an inline css, which I used for testing and it was apparently overriding my css file and I also didn't have ../../ thing at the time when I did not have inline css. So all together it didn't work and after I deleted inline css and added ../../ bit to my url path, it started work.

Thanks for your help
0
 
YurichAuthor Commented:
thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.