HTML base href 属性
htmlweb developmentfront end technology更新于 2025/3/22 10:52:17
<base> 元素的 href 属性设置所有相对 URL 的基准 URL。例如,所有相对 URL(例如 /html、/java、/jquery 等)的基准 URL 均为 https://example.com/tutorials,这些 URL 最终会以 − 结尾。
https://example.com/tutorials/html https://example.com/tutorials/java https://example.com/tutorials/jquery
以下是语法 −
<base href="absolute_URL">
以上,absolute _URL 是基准 URL 的绝对 URL。现在让我们看一个实现 元素的 href 属性的示例 −
示例
<!DOCTYPE html> <html> <head> <base href="https://www.example.com/tutorials/"> </head> <body> <h2>Tutorials List</h2> <p><a href="java.html">Java Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/java.html)</p> <p><a href="jquery.html">jQuery Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/jquery.html)</p> <p><a href="blockchain.html">Blockchain Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/blockchain.html)</p> <p><a href="python.html">Python Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/python.html)</p> </body> </html>
输出

在上面的例子中,我们将基本 URL 设置为 −
<base href="https://www.example.com/tutorials/">
之后,我们将链接设置为 "java.html",最终将充当 −
https://www.example.com/tutorials/java.html
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

