目錄
href 屬性在 HTML 中如何運作?
在 HTML 中實作 href 標籤的範例
範例#4 – 帶有 href 屬性的標籤
The tag with href attribute URLs Example
結論
推薦文章
首頁 web前端 html教學 HTML 中的 href 標籤

HTML 中的 href 標籤

Sep 04, 2024 pm 04:32 PM
html html5 HTML Tutorial HTML Properties HTML tags

HTML href 縮寫為超文本引用。這是錨點 () 標記內可用的屬性。此 href 用於 www.google.com、www.gmail.com、www.facebook.com 等網站 URL。

即時範例:日常生活中,我們造訪了許多網站。您有沒有想過我們如何造訪這個網站的網址?由於有了href標籤,我們可以訪問任何網站的URL。我們只需要 href 屬性的雙引號 (href=”website”) 內有一個網站。

href 屬性在 HTML 中如何運作?

HTML href 屬性的工作原理取決於我們使用的 href 標籤。所有可用的 href 標籤的目的都是相同的,用於存取 Web URL,但有一些細微的差別。

有 4 個標籤允許其中包含 href 屬性。他們是:

1。 此標籤用於指定連結必須位於 href 屬性內的頁面的 URL。

文法:

<a href="URL%20link"></a>
登入後複製

2。 此標籤用於指定連結必須位於 href 屬性內的頁面的 URL。

文法:

<area href="URL%20link">
登入後複製

 3. 此標籤用於指定連結必須位於 href 屬性內的所有相對頁 URL 的基本 URL。

文法:

<base href="Base%20URL%20link">
登入後複製

 4. 此標籤用於在 href 屬性中指定外部檔案位置,如 styles.css、javascript.js 等。

文法:

<link href="external%20link">
登入後複製

在 HTML 中實作 href 標籤的範例

以下是不同的範例:

範例 #1 – 帶有 href 屬性的標籤

代碼:


<title>href attribute</title>

<!--CSS code-->
<style>
p
{
color: green;
border: 2px solid brown;
font-size: 22px;
}
h1
{
color: blue;
text-align: center;
}
</style>


<h1>The <a> tag with href attribute introduction</a>
</h1>
<p>HTML href is abbreviated as hypertext reference. This is the attribute which is available inside the anchor (<a>) tag. This href is used for website URLs like www.google.com, www.gmail.com, www.facebook.com etc.</a></p>
<p>Real time Example: Day to day life we have accessed so many websites. Have you ever think about how would we access this website URLs? Because of href tag we can access any website URLs. We simply required website within this double quotes (href="website") of href attribute.
</p>
<h1>The <a> tag with href attribute URLs</a>
</h1>
登入後複製

輸出:

HTML 中的 href 標籤

範例 #2 – ;帶有 href 屬性的標籤

代碼:


<title>href attribute</title>

<!--CSS code-->
<style>
p
{
color: fuchsia;
border: 2px solid orange;
font-size: 22px;
}
h1
{
color: red;
text-align: center;
}
</style>


<h1>The <a> tag with href attribute introduction</a>
</h1>
<p>HTML href is abbreviated as hypertext reference. This is the attribute which is available inside the anchor (<a>) tag. This href is used for website URLs like www.google.com, www.gmail.com, www.facebook.com etc.</a></p>
<p>Real time Example: Day to day life we have accessed so many websites. Have you ever think about how would we access this website URLs? Because of href tag we can access any website URLs. We simply required website within this double quotes (href="website") of href attribute.
</p>
<h1 id="The-area-tag-with-href-attribute-URLs-Example">The <area> tag with href attribute URLs Example</h1>
<img src="/static/imghw/default1.png" data-src="planets.gif" class="lazy"    style="max-width:90%"  style="max-width:90%" alt="HTML 中的 href 標籤" usemap="#educba">
<map name="educba">
<!--Click on this coordinate gives you that images-->
<area shape="rect" coords="0,0,81,125" href="sun.htm">
<area shape="circle" coords="91,59,4" href="mercur.htm">
<area shape="circle" coords="125,59,9" href="venus.htm">

</map>
登入後複製

輸出:

HTML 中的 href 標籤

點擊後

HTML 中的 href 標籤

範例 #3 – 帶有 href 屬性的標籤

代碼:


<title>href attribute</title>

<!--From this path image is loaded-->
<base href="https://www.w3schools.com/images/">
<!--CSS code-->
<style>
p
{
color: navy;
border: 2px solid blue;
font-size: 22px;
}
h1
{
color: fuchsia;
text-align: center;
}
</style>


<h1>The <a> tag with href attribute introduction</a>
</h1>
<p><img  src="/static/imghw/default1.png" data-src="stickman.gif" class="lazy"    style="max-width:90%"  style="max-width:90%" alt="HTML 中的 href 標籤" > HTML href is abbreviated as hypertext reference. This is the attribute which is available inside the anchor (<a>) tag. This href is used for website URLs like www.google.com, www.gmail.com, www.facebook.com etc.</a></p>
<p>Real time Example: Day to day life we have accessed so many websites. Have you ever think about how would we access this website URLs? Because of href tag we can access any website URLs. We simply required website within this double quotes (href="website") of href attribute.
</p>

登入後複製

輸出:

HTML 中的 href 標籤

範例#4 – 帶有 href 屬性的標籤

代碼:


<title>href attribute</title>

<!--Including external CSS styles file with link tag-->
<link rel="stylesheet" type="text/css" href="styles.css">


<h1>The <a> tag with href attribute introduction</a>
</h1>
<p>HTML href is abbreviated as hypertext reference. This is the attribute which is available inside the anchor (<a>) tag. This href is used for website URLs like www.google.com, www.gmail.com, www.facebook.com etc.</a></p>
<p>Real time Example: Day to day life we have accessed so many websites. Have you ever think about how would we access this website URLs? Because of href tag we can access any website URLs. We simply required website within this double quotes (href="website") of href attribute.
</p>

登入後複製

CSS 代碼:styles.css

p
{
color: red;
border: 2px solid green;
font-size: 22px;
}
h1
{
color: orange;
text-align: center;
}
登入後複製

輸出:
HTML 中的 href 標籤

結論

hrefin HTML 用於存取 Web URL。允許使用 href 屬性的標籤有 等。和。最常見的是和使用標籤。

推薦文章

這是 HTML 中 href 標籤的指南。在這裡,我們討論 HTML 中 href 標籤的簡介及其範例以及程式碼實作和輸出。您也可以瀏覽我們推薦的文章以了解更多資訊 –

  1. HTML 中 Span 標籤的前 15 個屬性
  2. div 標籤在 HTML 中如何運作?
  3. HTML 搜尋列 |範例
  4. HTML 中的畫布標籤 |範例

以上是HTML 中的 href 標籤的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1658
14
CakePHP 教程
1415
52
Laravel 教程
1309
25
PHP教程
1257
29
C# 教程
1231
24
HTML 中的表格邊框 HTML 中的表格邊框 Sep 04, 2024 pm 04:49 PM

HTML 表格邊框指南。在這裡,我們以 HTML 中的表格邊框為例,討論定義表格邊框的多種方法。

HTML 中的巢狀表 HTML 中的巢狀表 Sep 04, 2024 pm 04:49 PM

這是 HTML 中巢狀表的指南。這裡我們討論如何在表中建立表格以及對應的範例。

HTML 左邊距 HTML 左邊距 Sep 04, 2024 pm 04:48 PM

HTML 左邊距指南。在這裡,我們討論 HTML margin-left 的簡要概述及其範例及其程式碼實作。

HTML 表格佈局 HTML 表格佈局 Sep 04, 2024 pm 04:54 PM

HTML 表格佈局指南。在這裡,我們詳細討論 HTML 表格佈局的值以及範例和輸出。

HTML 輸入佔位符 HTML 輸入佔位符 Sep 04, 2024 pm 04:54 PM

HTML 輸入佔位符指南。在這裡,我們討論 HTML 輸入佔位符的範例以及程式碼和輸出。

您如何在PHP中解析和處理HTML/XML? 您如何在PHP中解析和處理HTML/XML? Feb 07, 2025 am 11:57 AM

本教程演示瞭如何使用PHP有效地處理XML文檔。 XML(可擴展的標記語言)是一種用於人類可讀性和機器解析的多功能文本標記語言。它通常用於數據存儲

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在這裡我們也分別討論了 HTML 有序列表和類型的介紹以及它們的範例

HTML onclick 按鈕 HTML onclick 按鈕 Sep 04, 2024 pm 04:49 PM

HTML onclick 按鈕指南。這裡我們分別討論它們的介紹、工作原理、範例以及各個事件中的onclick事件。

See all articles