2

I'm new in asp.net. And I am having trouble setting my background image. Here's the master page source:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master.master.cs" Inherits="Master"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link rel="stylesheet" type="text/css" href="scripts/style.css"/>
    <title>Tracker</title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div class="container">
                <a href="#"><img src="images/cross-header.gif" alt="Insert Logo Here" width="100%" id="Insert_logo" style="background: #C6D580; display:block;" /></a>

            <div class="sidebar1">
                <nav>
                    <ul>
                        <li><a href="#">Home</a></li>
                        <li><a href="#">LINK</a></li>
                        <li><a href="#">LINK</a></li>
                        <li><a href="#"><span style="font-weight:italic">LINK</span></a></li>
                        <li><a href="#"><span style="font-weight:italic">LINK</span></a></li>
                    </ul>
                </nav>
                    <p>SOME LABEL</p>
                    <p>SOME QUOTE HERE</p>
                    <p></p>
            </div>
        </div>
        <footer>
           <a href="#">LINK HERE</a> | <a href="#">LINK HERE</a> | 
           <a href="contact.php">CONTACT</a> | <a href="register.php">REGISTER</a> | <a href="login.php">LOGIN</a>
            <address>
                Copyright 2012 @JRC
            </address>
        </footer>
    </div>
    </form>
</body>
</html>

The image that I am trying to use is located at the folder image. I don't know whats wrong.

And here's what the style.css source:

body 
{
    font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;

    background-image:url('images/background.jpg');
    background-repeat:no-repeat;
    background-attachment:scroll;
    background-position:repeat-x;
}

I also tried this url('image/background.jpeg') etc. but still fails.

2
  • Where is your style sheet located in the directory structure? Commented Dec 2, 2012 at 5:07
  • it is located at style folder. But as 'tjcertified' suggested, I tried to put my style.css in the same folder of my background image (image folder) and it still fails. :( Commented Dec 2, 2012 at 5:13

4 Answers 4

12

This largely depends on where your css file is located. If it is located in the same folder where the 'image' folder is located, then this looks correct. However, if you css file is in a different directory (say /css) then your link in your css file will not work. Instead, either change the css link to point to a complete link:

background-image: url('http://mysite.com/images/background.jpg)

I am unsure if the '~' link will work in a stylesheet. Since your css is in the scripts folder, you should be able to do this:

background-image: url('../images/background.jpg')
Sign up to request clarification or add additional context in comments.

2 Comments

I already solve my problem, thanks for your great answer. 45 secs left to mark your answer as the best answer. thanks again! :)
Sorry, edits should make this more clear. I didn't look carefully at your master page first. If the css is working as is, leave it in the 'scripts' folder, and use the second link, and all should be well.
0

This worked for me :

background-image: url(<%=ResolveClientUrl("~/images/background.jpg")%>);

Comments

-1

it is getting confuse, because of your src, it finding it in current_folder+src, but your image folder is in root folder, for that to reach root_folder+src you have to prefix your source with ~/

background-image:url('~/images/background.jpg');

1 Comment

Thanks for that info, but it still fails even I did that. :(
-1

Add master page, then link css script and paste the link of CSS using drag and drop method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.