Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính href của <base> trong HTML


Giới thiệu

Thuộc tính href của phần tử <base> thiết lập URL cơ sở (base URL) cho tất cả các URL tương đối (relative URLs) trong tài liệu. Chỉ được phép có một thẻ <base> và phải nằm trong <head>.

Cú pháp

<base href="URL_tuyet_doi">

Ví dụ minh họa

<!DOCTYPE html>
<html>
<head>
  <base href="https://www.example.com/tutorials/">
</head>
<body>
  <h2>Danh sách hướng dẫn</h2>
  <p><a href="java.html">Java Tutorial</a></p><p>(Sẽ giải析 thành https://www.example.com/tutorials/java.html)</p>
  <p><a href="jquery.html">jQuery Tutorial</a></p><p>(Sẽ giải析 thành https://www.example.com/tutorials/jquery.html)</p>
  <p><a href="blockchain.html">Blockchain Tutorial</a></p><p>(Sẽ giải析 thành https://www.example.com/tutorials/blockchain.html)</p>
  <p><a href="python.html">Python Tutorial</a></p><p>(Sẽ giải析 thành https://www.example.com/tutorials/python.html)</p>
</body>
</html>

Kết quả hiển thị

Liên kết tương đối java.html tự động trở thành URL tuyệt đối dựa trên base href.

<base href="https://www.example.com/tutorials/">