Html 在html中选择父目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19977506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting a parent directory in html
提问by Falcon
I have a general question (I'm not all to familiar with html).
我有一个一般性问题(我并不完全熟悉 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?
是否有指向父目录的 html 等效项?
回答by Kuzgun
../
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
将是父目录中的图像文件夹
回答by Lave Loos
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".
因此,假设您在名为“styles.css”的 CSS 文件中为图像制定了样式规则。
- The location of the stylesheet is C:\MyApp\CSS\styles.css.
- The location of the image is: C:\MyApp\Image\my_Image.png.
- 样式表的位置是 C:\MyApp\CSS\styles.css。
- 图片的位置是: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:
读取 CSS 时,它将是用于当前位置的 css 文件的位置。所以如果你想得到你的图像,你可以这样指向它:
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:
如果图像的位置直接在 C:\ 上,则必须返回两个父目录:
background: url("../../my_Image.png") no-repeat scroll 0 0 transparent;
This principle also goes for JavaScript files and so on.
这个原则也适用于 JavaScript 文件等。
回答by H3sDW11e
It works perfectly also together with a <base>
tag;
它也可以与<base>
标签完美配合;
example
例子
<head>
<base href="resources\">
</head>
then from the root index: <a href="template\sample1.html">sample1</a>
然后从根索引: <a href="template\sample1.html">sample1</a>
<head>
<base href="..\resources\">
</head>
then from the template: <img src="images\sample1.jpg">
然后从模板: <img src="images\sample1.jpg">
working with a directory structure like:
使用目录结构,如:
index.html
resources\template\
resources\images\
index.html
资源\模板\
资源\图像\