background-image in external css

Discussion in 'ASP .Net' started by =?Utf-8?B?RGFuIE5hc2g=?=, Aug 2, 2004.

  1. Hi

    I'm trying to create an external stylesheet for use in my Web App. It works fine, and I've got it linked and everything. The only problem is the "background-image" property isn't working.

    I've selected the iamge through VS, and its in the _images/ subdir. The code that VS created is as follows:

    background-image: url(_images/back.jpg)

    Yet it doesn't work. The image appears in the CSS style editor, but when I run my app in the browser, no image is displayed. All other tags seem fine though. Any ideas...?

    Cheers


    Dan
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 2, 2004
    #1
    1. Advertising

  2. "Dan Nash" <> wrote in message
    news:...
    > Hi
    >
    > I'm trying to create an external stylesheet for use in my Web App. It

    works fine, and I've got it linked and everything. The only problem is the
    "background-image" property isn't working.
    >
    > I've selected the iamge through VS, and its in the _images/ subdir. The

    code that VS created is as follows:
    >
    > background-image: url(_images/back.jpg)
    >
    > Yet it doesn't work. The image appears in the CSS style editor, but when I

    run my app in the browser, no image is displayed. All other tags seem fine
    though. Any ideas...?

    "_images/back.jpg" is a relative URL. I bet that in the style editor, it is
    relative to the page, but that when the external stylesheet is used, the URL
    is taken to be relative to the URL of the external stylesheet. For instance,
    if the stylesheet was at http://site/styles/mycss.css, then I bet that the
    image URL would mean http://site/styles/_images/back.jpg.

    Just a guess. Try an absolute URL just to see what happens.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Aug 2, 2004
    #2
    1. Advertising

  3. Thanks John,

    You're dead on. Path was wrong. It was actually pointing at http://website/_shared/_css/_img/backtest.jpg - not much good!

    A simple "../../" sorted it! :eek:)

    Thanks a lot!


    Dan

    "John Saunders" wrote:

    > "Dan Nash" <> wrote in message
    > news:...
    > > Hi
    > >
    > > I'm trying to create an external stylesheet for use in my Web App. It

    > works fine, and I've got it linked and everything. The only problem is the
    > "background-image" property isn't working.
    > >
    > > I've selected the iamge through VS, and its in the _images/ subdir. The

    > code that VS created is as follows:
    > >
    > > background-image: url(_images/back.jpg)
    > >
    > > Yet it doesn't work. The image appears in the CSS style editor, but when I

    > run my app in the browser, no image is displayed. All other tags seem fine
    > though. Any ideas...?
    >
    > "_images/back.jpg" is a relative URL. I bet that in the style editor, it is
    > relative to the page, but that when the external stylesheet is used, the URL
    > is taken to be relative to the URL of the external stylesheet. For instance,
    > if the stylesheet was at http://site/styles/mycss.css, then I bet that the
    > image URL would mean http://site/styles/_images/back.jpg.
    >
    > Just a guess. Try an absolute URL just to see what happens.
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    >
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 3, 2004
    #3
  4. =?Utf-8?B?RGFuIE5hc2g=?=

    Guest

    Hi

    your css is invalid

    background: url(whatever.jpg);

    **********************************************************************
    Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    , Aug 3, 2004
    #4
  5. Hi Armand

    My CSS now reads...

    background-image: url(../../_img/backtest.jpg);

    I wonder if you could tell me how this is invalid? If (as you mentioned) my code read

    background-image: url(backtest.jpg);

    That would mean that my JPG file would have to be located in the _shared/_css folder, which, I'm sure you'll agree makes for a very messy and confusing directory structure. For my CSS to work from it's location, I need to get back to the root and find _img/backtest.jpg. So.. how do I do that without making it invalid?

    If, As John suggested, I use an absolute reference, I get

    background-image: url(http://localhost/DearPrimeMinister/_img/backtest.jpg);

    I'm assuming that when I move my project to my web server, all the links will be invalid, because all the links point to localhost rather than www.mysite.com. Unless of course localhost works on Win2k3 servers as well...?

    Can you clarify, just so I know I'm doin it right. :eek:)

    Cheers


    Dan


    "Armand" wrote:

    > Hi
    >
    > your css is invalid
    >
    > background: url(whatever.jpg);
    >
    > **********************************************************************
    > Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    > Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    >
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 3, 2004
    #5
  6. Hi Armand

    My CSS now reads...

    background-image: url(../../_img/backtest.jpg);

    I wonder if you could tell me how this is invalid? If (as you mentioned) my code read

    background-image: url(backtest.jpg);

    That would mean that my JPG file would have to be located in the _shared/_css folder, which, I'm sure you'll agree makes for a very messy and confusing directory structure. For my CSS to work from it's location, I need to get back to the root and find _img/backtest.jpg. So.. how do I do that without making it invalid?

    If, As John suggested, I use an absolute reference, I get

    background-image: url(http://localhost/DearPrimeMinister/_img/backtest.jpg);

    I'm assuming that when I move my project to my web server, all the links will be invalid, because all the links point to localhost rather than www.mysite.com. Unless of course localhost works on Win2k3 servers as well...?

    Can you clarify, just so I know I'm doin it right. :eek:)

    Cheers


    Dan


    "Armand" wrote:

    > Hi
    >
    > your css is invalid
    >
    > background: url(whatever.jpg);
    >
    > **********************************************************************
    > Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    > Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    >
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 3, 2004
    #6
  7. Hi Armand

    My CSS now reads...

    background-image: url(../../_img/backtest.jpg);

    I wonder if you could tell me how this is invalid? If (as you mentioned) my code read

    background-image: url(backtest.jpg);

    That would mean that my JPG file would have to be located in the _shared/_css folder, which, I'm sure you'll agree makes for a very messy and confusing directory structure. For my CSS to work from it's location, I need to get back to the root and find _img/backtest.jpg. So.. how do I do that without making it invalid?

    If, As John suggested, I use an absolute reference, I get

    background-image: url(http://localhost/DearPrimeMinister/_img/backtest.jpg);

    I'm assuming that when I move my project to my web server, all the links will be invalid, because all the links point to localhost rather than www.mysite.com. Unless of course localhost works on Win2k3 servers as well...?

    Can you clarify, just so I know I'm doin it right. :eek:)

    Cheers


    Dan


    "Armand" wrote:

    > Hi
    >
    > your css is invalid
    >
    > background: url(whatever.jpg);
    >
    > **********************************************************************
    > Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    > Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    >
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 3, 2004
    #7
  8. Hi Armand

    My CSS now reads...

    background-image: url(../../_img/backtest.jpg);

    I wonder if you could tell me how this is invalid? If (as you mentioned) my code read

    background-image: url(backtest.jpg);

    That would mean that my JPG file would have to be located in the _shared/_css folder, which, I'm sure you'll agree makes for a very messy and confusing directory structure. For my CSS to work from it's location, I need to get back to the root and find _img/backtest.jpg. So.. how do I do that without making it invalid?

    If, As John suggested, I use an absolute reference, I get

    background-image: url(http://localhost/DearPrimeMinister/_img/backtest.jpg);

    I'm assuming that when I move my project to my web server, all the links will be invalid, because all the links point to localhost rather than www.mysite.com. Unless of course localhost works on Win2k3 servers as well...?

    Can you clarify, just so I know I'm doin it right. :eek:)

    Cheers


    Dan


    "Armand" wrote:

    > Hi
    >
    > your css is invalid
    >
    > background: url(whatever.jpg);
    >
    > **********************************************************************
    > Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    > Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
    >
    =?Utf-8?B?RGFuIE5hc2g=?=, Aug 3, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noozer
    Replies:
    5
    Views:
    52,311
  2. John Seeliger
    Replies:
    6
    Views:
    6,602
  3. jc
    Replies:
    3
    Views:
    1,717
  4. jc
    Replies:
    1
    Views:
    1,358
    Neredbojias
    Mar 19, 2008
  5. Dj Frenzy
    Replies:
    3
    Views:
    298
    Robert
    Feb 10, 2004
Loading...

Share This Page