Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i use in external stylesheet that
body{

background-image: url(images/bg-body.png);
}

no image is added but when i use this instead of above

background-image: url(../images/bg-body.png);

i use .. before /images directory

the image is loaded in background,,

so what (.. this dots means here that worked for me,
Posted
Updated 8-Jul-15 2:26am
v2

In addition to Solution 1:

Most likely, what you wanted to achieve was referencing your "bg-body.png" relative to the root directory set up for your site. Right syntax for that would be "~/images/bg-body.png".

The path "/images/bg-body.png" is something different; this is a path relative to the current point, the location of the file referencing this file. It assumes that the directory, the one where your HTML file is located, has sub-directory "images" and that this sub-directory has the file "bg-body.png". Apparently, in your example, this is not the case.

In cases like yours, using his "~/" "site-global" paths gives you one benefit in maintenance: when you move HTML files referencing, say, image files this way, and don't move the directory with images, the references remain valid. With relative addressing (best in many other cases), you would need to edit them in the HTML files if you change their locations in certain way, say, chance the depth of their directories.

—SA
 
Share this answer
 
v2
Comments
Peter Leow 8-Jul-15 12:36pm    
5ed for making it complete.
Sergey Alexandrovich Kryukov 8-Jul-15 15:08pm    
Thank you, Peter.
—SA
..

refers to the parent of the current directory
parent directory (..) ----
                         |----images directory ----
                         |                        |
                         |                    bg-body.png
                         | 
                         |----webpage directory ---
                                                  | 
                                yourpage.html (referencing the bg-body.png)

Read more: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#fully_qualified_vs._relative_paths[^]
 
Share this answer
 
v5
Comments
Sergey Alexandrovich Kryukov 8-Jul-15 11:52am    
Correct but a bit incomplete; so I voted 4 this time.
It could be helpful if you also explained '~/...', because, most likely, this is what the inquirer really tried to implement: to file path relative to the root directory of the site. So, something like "~/images/bg-body.png" would also work.
—SA
Sergey Alexandrovich Kryukov 8-Jul-15 12:02pm    
I even added Solution 2 to clarify it.
—SA
Peter Leow 8-Jul-15 12:36pm    
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900