如何使用 <base> 标签定义 HTML 页面的基准 URL?
htmlweb developmentfront end technology更新于 2024/6/7 5:32:17
在本文中,我们将学习如何使用 <base> 标签定义 HTML 页面的基准 URL。
在 HTML 中,不同的元素具有包含指向其他资源的链接的属性。这些属性的值是 URL,可以是绝对 URL 或相对 URL。
HTML 元素 <base> 指定文档中所有相对 URL 使用的基准 URL。一个文档中只能有一个 <base> 元素,并且必须放在 <head> 标签内。
以下是 HTML 标签的属性 -
<base>标签必须包含 href 或 target 属性,或两者皆有。
| 序号 | 属性和说明 |
|---|---|
| 1 | href 基本 URL |
| 2 | target 目标 URL 的打开位置 − _blank - 目标 URL 将在新窗口或标签页中打开。 _self - 目标 URL 将在点击时所在的框架中打开。 _parent - 目标 URL 将在父框架集中打开 _top - 目标 URL 将在顶部框架中打开,即整个窗口主体。 |
语法
<base herf= "base link…" target= "value"/>
示例 1
以下是使用 <base> 定义基本 URL 的示例HTML 中的标签 –
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Declaring the BASE URL --> <base href="C:\Users\LOKESH BADAVATH\OneDrive\Desktop\TUTORIAL'S POINT\images\"target="_blank"/> </head> <body> <img src="https://www.cainiaomax.com/static/images/logo-color.png" /> </body> </html>
Example 2
Another example to define the base URL using the tag is as follows −
<!DOCTYPE html> <html> <head> <title>HTML base Tag</title> <base href = "http://www.tutorialspoint.com" /> </head> <body> HTML: <br><img src = "https://tutorialspoint.com/images/html.gif" /> </body> </html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

