0

I'm trying to set an image as a background image. From what I've read – I need to have a tilde (~) before the address or the site won't function if put inside a folder. But though that works when I do the following (which doesn't get the result I want because it's not a background image):

<asp:Image ID="MyImage" runat="server" ImageUrl="~/images/Image1.png"/>

It doesn’t work in where I need it to work:

<body style="background-image: url(~/images/Image1.png) ; background-position: left top; background-repeat: no-repeat">

Adding that tilde there causes the image to disappear.

So how do I add the tilde to a background image? (And why doesn't it work there?)

EDIT: I tried having just:

background-image: url(images/topleft.png)

(without the first forwardslash) but then any page inheriting from this page (which is a master page) didn't "find" the image.

2 Answers 2

3

Things are easier if you move all your styles into css, that way you don't have any problems resolving URLs because they're all relative to the location of your stylesheet.

3
  • Thanks. Is there a simple way in VWD to add a style for something in the stylesheet?
    – ispiro
    Jun 13, 2012 at 12:20
  • Css syntax is very similar to inline style syntax. Add a css stylesheet to your project and then write body{ background-image:url(topleft.gif); background-position: top left;} Jun 13, 2012 at 12:28
  • Thanks. That worked (though I had to change it to:url(../images/topleft.png)). But it seems like there ought to be a simple way to do this with the designer.
    – ispiro
    Jun 13, 2012 at 12:37
0

Is your css file in the root folder? May be your pages not finding css file or not same url for all the pages(pages that kept in different folder)? please make sure you have the correct directory structure:

+--Root folder

  +--Css (folder)
     \--Stylesheet.css

  +--Images (folder)
    \--image.jpg

  +--Pages (folder)
    \--mypage.aspx

 \--Default.aspx

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.