Selecting a parent directory in html

≡放荡痞女 提交于 2019-11-30 02:46:16

../ 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

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.

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\

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!