HTML <base>标签
HTML <base>标签的作用
HTML <base>标签用于指定基本URI或URL,以用于HTML文档中包含的所有相对链接。
在文档中只能指定一个<base>元素,并且必须将其放置在<head>元素中。我们还可以使用target属性指定如何打开其他链接(在同一窗口,在另一个窗口等)。
语法
<base href="https://www.lidihuo.com">
在HTML <base>元素中不包含结束标签,但在XHTML结束标签中</base>是必需的。
以下是有关 <base>标签的一些规范
项 |
说明 |
开始标签/结束标签 |
仅开始标签 |
用法 |
锚点和链接 |
示例
在同一窗口中打开(默认情况下)
<!DOCTYPE html>
<html>
<head>
<title>Base tag</title>
<style>
a{text-decoration: none;
color:black;}
a:hover{color: green;
font-size: 18px;}
</style>
<base href="https://www.lidihuo.com">
</head>
<body>
<h2 style="color: red; font-size: 30px; font-style: italic;">Web开发教程列表</h2>
<a href="/html/html-index.html">HTML tutorial</a><br>
<a href="/css/css-index.html">CSS tutorial</a><br>
<a href="/bootstrap/bootstrap-index.html">Bootstrap tutorial</a><br>
<a href="/javascript/javascript-index.html">JavaScript tutorial</a><br>
<a href="/jquery/jquery-index.html">JavaScript tutorial</a>
</body>
</html>
在新窗口中打开(使用 标签中的_blank):
<!DOCTYPE html>
<html>
<head>
<title>Base 标签</title>
<style>
a{text-decoration: none;
color:black;}
a:hover{color: green;
font-size: 18px;}
</style>
<base href="https://www.lidihuo.com" target="_blank">
</head>
<body>
<h2 style="color: red; font-size: 30px; font-style: italic;">Web开发教程列表</h2>
<a href="/html/html-index.html">HTML tutorial</a><br>
<a href="/css/css-index.html">CSS tutorial</a><br>
<a href="/bootstrap/bootstrap-index.html">Bootstrap tutorial</a><br>
<a href="/javascript/javascript-index.html">JavaScript tutorial</a><br>
<a href="/jquery/jquery-index.html">JavaScript tutorial</a>
</body>
</html>
在上面的示例中,我们仅在
标签中使用了
target =" _ blank" ,但它应用于整个文档链接。
属性
标签特定属性:
属性 |
值 |
定义 |
href |
URL |
它指定所有相对链接的基本URL。 |
目标 |
_blank |
在新窗口中打开相对链接 |
_self |
在当前窗口中打开相对链接 |
_parent |
在父框架中打开相对链接 |
_top |
打开页面全宽度的链接 |
全局属性
标签支持HTML中的所有全局属性
事件属性
不支持HTML中的事件属性
支持浏览器