<base>
标签用于指定页面中所有相对URL的基础URL。它有以下几个属性:
href
:指定基础URL。通常是网站根目录的URL,可以使用绝对URL或相对URL。target
:指定链接在何处打开。常用的值包括_self
(在当前窗口中打开)、_blank
(在新窗口中打开)等。举个例子,在以下代码中:
<head>
<base href="https://example.com/home/" target="_blank">
</head>
<body>
<a href="about.html">About Us</a>
<a href="/contact/">Contact Us</a>
<a href="https://example.com/blog/">Blog</a>
</body>
所有没有以http
或https
开头的链接都会被解释为相对于https://example.com/home/
的URL。因此,第一个链接会被解析为https://example.com/home/about.html
,第二个链接为https://example.com/contact/
,第三个链接则不受影响。
请注意,除非其中一些属性(例如target
)需要更改,否则应该只出现一个 <base>
标签,而且必须放在 <head>
标签中。