-1

The more I work with CSS, the more depression I get I want to set a background picture stored on the same folder where my aspx and cs files are located, still it wont put a background picture:

/* DEFAULTS
----------------------------------------------------------*/

body   
{
    background-image:url(banner.gif);
    display:block; // have tried without it as well, no change :(
}

Default.aspx:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server">

            <asp:ContentPlaceHolder ID="MainContent" runat="server">

            </asp:ContentPlaceHolder>

    </form>
</body>
</html>

Please help how to set the background picture ?

Usman Waheed
  • 555
  • 5
  • 14
  • 2
    Is that in an external file? The path to the image needs to be relative to the CSS file. – Martin Smith May 13 '13 at 09:14
  • 1
    are you sure the image is correctly referenced? because as it stands banner.gif would have to be located in the root of the ~/Styles directory – Nicholas King May 13 '13 at 09:16
  • check your browser's dev tools and look at the http requests being made. I'd be willing to bet that the browser is trying to load the image but it's getting a 404 error. You probably just need to change the path. Oh, and the `display:block` is completely unnecessary; that's the default for the body element anyway. – Spudley May 13 '13 at 09:17
  • background-image:url('banner.gif'); note the two `'` i added – DiederikEEn May 13 '13 at 09:18
  • @DiederikEEn - [Quotes are not required](http://stackoverflow.com/q/851724/73226) – Martin Smith May 13 '13 at 09:19
  • No luck, tried with surrounding with single quotes yes the structure is: Root: - Styles (folder) --it contains a css file: Site.css, whose CSS I posted in start - banner.gif - Site.Master - Default.aspx after all its just a simple Asp.Net web application created using VS 2010 – Usman Waheed May 13 '13 at 09:27
  • Please do not answer your question with 'additional details'. You can edit your question or post comments. – webketje May 13 '13 at 09:45
  • @UsmanWaheed remove the ~ from ` – DiederikEEn May 13 '13 at 09:58

2 Answers2

0

You said that your CSS and image are in same folder where you've your aspx file and CSS so

First try setting a background color for body say

body {
   background: #f00; /*This should give you red*/
}

If this works than fine, something is wrong with the image path, if you fail to see the color too, that means your stylesheet is at the wrong path, so instead of

<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

Should be

<link href="Site.css" rel="stylesheet" type="text/css" />
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0

here is the image, I dont thin there is any problem with paths: enter image description here

Usman Waheed
  • 555
  • 5
  • 14
  • ignore the inline body styling as only thing works my requirement is to get it work from Site.css file I m using Windows XP, VS 2010 – Usman Waheed May 13 '13 at 09:39