Selecting a parent directory in html

2019-02-02 04:56发布

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?

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-02 05:16

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.

查看更多
冷血范
3楼-- · 2019-02-02 05:21

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

查看更多
在下西门庆
4楼-- · 2019-02-02 05:26

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\

查看更多
登录 后发表回答