0

i want to set a background image in a application and image goes in my application is

application /images/ --> images is here

but when application hosted the background image not worked because path i given based on current settings who broken when application hosted in subdomain.

how i can set it dynamically

1 Answers1

2

You use relative paths in a .css file, they are relative to the location of the stylesheet, not the location of the current page:-

a.external
{
  background-image:url('external-link.gif');
  background-repeat:no-repeat;
}

will look for an image called 'external-link.gif' in the same directory as the .css file.

So if your directory structure looks like:-

  • {Domain Root}
  • Content
  • Content\Style.css
  • Images
  • Images\MyImage.png

you could reference MyImage.png from Style.css with:-

url('../Images/MyImage.png')

Then if you moved your application into a subdirectory:-

  • {Domain Root}
  • Site
  • Site\Content
  • Site\Content\Style.css
  • Site\Images
  • Site\Images\MyImage.png

The same url ('../Images/MyImage.png') still finds the image because the relative path between the two resources has not changed.

See also:

Community
  • 1
  • 1
Iain Galloway
  • 18,669
  • 6
  • 52
  • 73