首页 > 解决方案 > 如何相对链接到 HTML 中的子文件夹?

问题描述

/foo我想链接到的页面上/foo/bar<a href="./foo/bar">有效,但它要求我知道我目前在/foo.

有没有一种方法可以让我在不需要知道当前路径的情况下附加一个后缀?

标签: html

解决方案


在“html”“head”中,您可以定义基本路径,所有其他 href 都可以相对于该基本路径。“base”标签的一些例子:

<base href="https://www.example.com/">
<base target="_blank"> 
<base target="_top" href="https://example.com/">

推荐阅读