1

I put the file under the "Styles" directory of my VS project, where my default sitemaster's CSS is located upon creation.

    body{
    background-image: url('..\Styles\Header.jpg');
    }

How can I use this properly to display the image in the background using external CSS?

4 Answers 4

1

try this in your css

body{
     background-image: url('~/Styles/Header.jpg');
}

or

 body{
         background-image: url('../Styles/Header.jpg');
    }

if your image is stored in Style forlder you can retrive by this code

Sign up to request clarification or add additional context in comments.

1 Comment

The first choice worked for me. For still some odd reason even with hard-tried research, not all of these codes work perfectly for everyone. I'm still not sure why. :( Anyhow thanks everyone!
1

Try this it works for me

 background-image: url(..\Styles\Header.jpg);

don't use single quote inside brackets.

2 Comments

Amit, can you please explain why not use single "quotes"
@KheemaPandey I don't know but I face same problem and resolved after removing the single quote and one more important point it works on all browsers.
1

HTML

<html>
<head>

<title> Your page Name </title>
<link rel="stylesheet" type="text/css" href="yourcssresourcefile">
</head>

<body>
</body>

</html>

CSS

   body{
    background-image: url('http://static3.businessinsider.com/image/52a0bbfd6bb3f7961363819e/the-most-amazing-satellite-images-of-the-year.jpg');
    }

Fiddle

Result

Comments

1

There are two approaches to do it;

when you are trying to access your resource (image) with relative path:

body{
         background-image: url('../Styles/Header.jpg');
    }

when you are trying to access you resource (image) with absolute path :

body{
     background-image: url('~/Styles/Header.jpg');
}

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.