Selecting a parent directory in html
Solution 1
../
will give you one level higher parent directory. You can use as much as you want to go higher level parents like ../../
../Image/my_Image.png
will be Image folder in parent directory
Solution 2
Single dot = current directory, double dot is parent directory...
./ = current
../ = parent
So let's say you have a style rule for an image in a CSS file called "styles.css".
- The location of the stylesheet is C:\MyApp\CSS\styles.css.
- The location of the image is: C:\MyApp\Image\my_Image.png.
When the CSS is being read, it will be the location of that css file that's used for the current location. So if you want to get to your image, you can point it like this:
background: url("../Image/my_Image.png") no-repeat scroll 0 0 transparent;
If the location of the image would have been directly on C:\, you would have to go back two parent directories:
background: url("../../my_Image.png") no-repeat scroll 0 0 transparent;
This principle also goes for JavaScript files and so on.
Solution 3
It works perfectly also together with a <base>
tag;
example
<head>
<base href="resources\">
</head>
then from the root index: <a href="template\sample1.html">sample1</a>
<head>
<base href="..\resources\">
</head>
then from the template: <img src="images\sample1.jpg">
working with a directory structure like:
index.html
resources\template\
resources\images\
Related videos on Youtube
Falcon
Updated on July 09, 2022Comments
-
Falcon almost 2 years
I have a general question (I'm not all to familiar with html).
The following use of the slash I have discovered points to a sub-directory, in this case for Images:
/Image/my_Image.png
Is there an html equivalent for pointing to a parent directory?