且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用整个地址的情况下链接到不同目录中的文件?

更新时间:2023-09-20 21:06:28

您可以使用两个像这样的点:



../然后你想要的目录,如标志或假设你在一个子目录中工作,如你所说的水果。


I'm building a website on my computer's local server, with the plan to upload to my webhost with all the links and relative pathways intact. However, I've run into a problem with how to link to pages and images in directories higher up the hierarchy chain.

For example, let say my website is about food and all my logos and stylesheets are in the main .com directory. Then I add the subdirectory "fruit". Sure, I could keep all my Fruit images in the fruit directory, but how would I link back to my logo and stylesheet, and still have links that work when I upload everything to my webhost? When I would edit websites online, just plugging in the whole address was no problem (caused issues if I ever wanted to change the domain, but it would work), but building a website offline on my computer is causing some organizational issues.

Help?

You can access the root directory using two dots like this:

../ and then your desired directory like logos or something assuming you are working inside a subdirectory as you mentioned "fruit".