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 Answer 1

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:

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

2 Comments

but application goes in sob-domain means broken the URL of image.
Not if you use a relative URL like I just described! The URLs in my post are relative to the location of the .css file. Edited my post.

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.