Liên kết SVG
Liên kết SVG - <a>
Phần tử <a>
được sử dụng để tạo liên kết.
Phần tử <a>
có thể được sử dụng với cả văn bản và đồ họa.
Phần tử <a>
có bảy thuộc tính cơ bản:
Attribute | Description |
---|---|
href | The URL to go to |
download | Tells the browser to download the URL instead of go to it |
hreflang | The language of the page the link points to |
referrerpolicy | The referrer to send when fetching the URL |
rel | The relationship of the target object to the link object |
target | Where to open the link. Can be _self, _parent, _top, _blank, or a name |
type | The MIME type for the linked URL |
Văn bản dưới dạng siêu liên kết
Văn bản dưới dạng liên kết (có phần tử <a>
):
Đây là mã SVG:
Ví dụ
<svg height="30" width="200" xmlns="https://www.w3.org/2000/svg">
<a href="https://www.example.com.vn/graphics/"
target="_blank">
<text x="5" y="15" fill="red">I love SVG!</text>
</a>
</svg>
Hãy tự mình thử »Giải thích mã:
- Thuộc tính
href
xác định URL cần truy cập - Thuộc tính
target
xác định nơi mở liên kết (ở đây liên kết sẽ mở trong cửa sổ/tab mới)
Đồ họa dưới dạng siêu liên kết
Vòng tròn dưới dạng liên kết (với phần tử <a>
):
Đây là mã SVG:
Ví dụ
<svg height="100" width="200" xmlns="https://www.w3.org/2000/svg">
<a
href="https://www.example.com.vn/graphics/" target="_blank">
<circle r="45" cx="50" cy="50" fill="red" />
</a>
</svg>
Hãy tự mình thử »