HTML 根文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15936201/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:25:35  来源:igfitidea点击:

HTML root folder?

html

提问by Caedan Lavender

Is there a way to direct a url such as an image location to your root folder and then into a directory from there.

有没有办法将 url(例如图像位置)定向到您的根文件夹,然后从那里定向到一个目录。

Currently i am using "../" to go back folders but this gets annoying if you have a complex directory tree.

目前我正在使用“../”返回文件夹,但如果您有一个复杂的目录树,这会很烦人。

Thanks

谢谢

回答by Hyman L.

It is just a single character:

它只是一个字符:

/

For example:

例如:

/image.jpg

whatever page you put it in, it refers to the same file, root_folder/image.jpg

无论你把它放在什么页面,它都指向同一个文件,root_folder/image.jpg

回答by Zach Lysobey

You can also use <base>to set the base url all urls should be relative to. In general using an absolute path with /is probably prefereable, but <base>may be useful if you have the "root" of your page noton the root of the domain. I.E. example.com/mysite/index.htmlvs. example.com

您还可以使用<base>设置所有 url 应该相对的基本 url。通常,使用绝对路径 with/可能更可取,但<base>如果您的页面的“根”不在域的根上,则可能会很有用。IEexample.com/mysite/index.html对比example.com

https://developer.mozilla.org/en-US/docs/HTML/Element/base

https://developer.mozilla.org/en-US/docs/HTML/Element/base

回答by Marcin Orlowski

You can just use full Url, like:

您可以使用完整的网址,例如:

http://domain.com/file_in_root_folder.jpg

or absolute paths

或绝对路径

/file_in_root_folder.jpg

回答by Mehdi Yeganeh

you can use static addressing that start with http:// and for relational addressing you can use your address with / for example: /foo/bar.jpg

您可以使用以 http:// 开头的静态寻址,对于关系寻址,您可以使用带有 / 的地址,例如:/foo/bar.jpg