Not with CSS. Am I right?
There are two kinds of addressing,
absolute and
relative. These both apply whether you're working from a server or your desktop. The mode of addressing in the CSS examples you're seeing are
relative.
Absolute addressing is merely specifying the entire path of the image from the root.
Relative is specifying the path
relative to the calling document, ie, your webpage.
Suppose you've created a hierarchy for your project on your hard drive and it looks like this:
C:/mywebsites/project_1
And you've created an HTML page in the project_1 directory, so its address looks like this:
C:/mywebsites/project_1/mywebpage.html
If you place the background image in the project_1 directory -- we'll call it bg.jpg -- it's in the same location
relative to the calling document, so the address would look just like the examples you've seen:
background-image:url(bg.jpg)
The
absolute address would look like this:
background-image:url(C:/mywebsites/project_1/bg.jpg)
The image and the HTML page using it are in the same place, so no path is needed for relative addressing. Just name the image.
Relative addressing has a couple of conventions that allow you to navigate the path from the calling document. One is the double-dot-slash (../). Each double-dot prepended to the address moves the home base of the address one directory higher. From the earlier example:
C:/mywebsites/project_1/mywebpage.html
Suppose you have have your images collected in a directory under 'mywebsites' called 'images', where the image 'bg.jpg' resides:
C:/mywebsites/images/bg.jpg
To address it
relatively, a single double-dot shifts the address base one level higher in the path, and you can complete the path from there:
background-image:url(../images/bg.jpg)
If it's two levels higher -- C:/images/bg.jpg -- use another double-dot:
background-image:url(../../images/bg.jpg)
Relative addressing has another shorthand, the single slash. That takes the base point all the way back to the root. This:
/images/bg.jpg
is equivalent to this:
http: //
