HTML 中的區域標記

王林
發布: 2024-09-04 16:31:03
原創
1004 人瀏覽過

在這篇文章中,我們將學習 HTML 中的區域標籤。區域標籤定義圖像映射中的熱點並與超文本引用相關聯或連結以允許使用者在網頁上可點擊。它有助於在單擊地圖部分時連結不同的頁面。當圖像上需要多個連結時,標籤就變得很有用。

文法

基本文法如下:

<area alt="text" class=" " coords=" " shape> ;
登入後複製

這裡 alt 用於在圖像未渲染時替換文字。

  • class: 定義元素的類別名稱。
  • 座標:具有一組形狀值。

對於圖像映射,語法是:

<img  html name src="path%20loacation" alt="HTML 中的區域標記" >
<map name=" name">
<area shape="shapeName1" coords="x,y coordinates" href="html%20linkPath">
<area shape="shapeName2" coords=" x,y coordinates " href="htmllinkPath">
</map>
登入後複製

說明: 這是一個沒有結束標籤的空標籤,而在 XHTML 中,它被宣告為 。並且此區域標籤始終嵌入 。標籤(包含在地圖容器中),它給出特定圖像的座標值。而且,不活動區域也會發生重疊;透過優先激活較高區域來解決。以下部分透過範例介紹如何使用區域標籤以及瀏覽器相容性及其支援的屬性。

區域標籤在 HTML 中如何運作?

這是完成它的過程;最初是影像圖中的影像。

1.要將圖像插入頁面,我們應該使用下面給出的圖像標籤:

<img src="edu.jpg" alt="HTML 中的區域標記 logo"> // image from the saved folder. Also, we can get from the web URL directly and map with <map> tag.</map>
登入後複製

它帶有 src 屬性:描述圖像內容的來源和替代文字。

2. 其次,開啟有#map屬性的地圖元素。該圖像標籤帶有一個 use map,後面跟著“#”符號(use map =“#map”)。地圖名稱應與使用地圖的名稱相同。

如何建立影像映射?一起使用地圖和名稱屬性可以將圖像和地圖放在一起。當滑鼠遊標在螢幕上變成指標(手形符號)時,瀏覽器會辨識形狀的區域。

3.聲明要用於映射的區域。

<area shape="rect" cords='…….href="" ' alt="">
href comes with alt attribute by default.
登入後複製

屬性

一般來說,HTML 標籤具有一個或多個屬性,有助於向瀏覽器展示令人愉悅的視覺效果。使用三種屬性,即全域屬性、事件處理屬性和特定於元素的屬性。區域標籤提供標籤特定的屬性及其描述,如下所列,且 HTML 5 有一些新屬性。

1.標籤特定屬性

屬性名稱  描述                  範例
替代 在指定區域定義替代文本,以提高可訪問性。
href 定義超級引用意味著指向下一頁點/頁面 URL 的連結。它將一個區域更改為超連結。 document”
形狀  定義要在影像上完成的不同形狀。 ”第一文檔”

”第二份文件”

座標 給出適合影像中區域的特定值。座標指定如下:

預設:不需要電線。

長方形:左、上、右、下

圓:x、y、半徑

Poly: x1,y1, x2,y2,x3,y3…

document”
target Specifies where to open the link page, or I can say the end target page. ”
Nohref Defines that absence of href. This means the area doesn’t have a link to next page
type Specifies the content type (MIME) ”Authors
hreflang Specifies language-type ”Second

2. Standard Attributes

The description of these attributes has already been discussed in the previous article.

  • Access key
  • class
  • dir
  • id
  • Style
  • lang
  • id
  • tab index
  • title.

3. Global Attributes

  • onmouse down
  • onmouse up
  • onmouse over
  • onmouse move
  • onmouse out
  • on focus
  • on blur
  • onkey press
  • onkey down
  • onkey up.

Examples to Implement Area Tags in HTML

Below are examples of implementing area tags in HTML:

Example #1

In the below example, I have created a jpg image diary.jpg. When u execute the code, the hand tool moves over the image at the specified cords; when you click on it, it directs you to the page rr.html.

Code:



<img  html src="diary.jpg" alt="HTML 中的區域標記" >
<map name="Diary">
<area shape="rect" coords="94,91,189,193" href="rr.html">
</map>

登入後複製

Code: rr.html



hello

 Online tutorial Class
登入後複製
登入後複製

Output:

HTML 中的區域標記

Example #2

Code:



<img src="edu.jpg" alt="HTML 中的區域標記 logo"    style="max-width:90%"  style="max-width:90%" html class="logo">
<map name="ccmap">
<area shape="rect" coords="89,9,294,50" href="sha.html" alt="HTML 中的區域標記">
<area shape="rect" coords="297,7,407,54" href="rr.html" alt="Welcome">
</map>

登入後複製

Code: rr.html



hello

 Online tutorial Class
登入後複製
登入後複製

Code: sha.html



hello

 Welcome to the Page
登入後複製

Output:

HTML 中的區域標記

The Output below shows the logo of HTML 中的區域標記; clicking the word BA directs to the page Hello page.

HTML 中的區域標記

Example #3

Code:



<img src="new.png" alt="HTML 中的區域標記" border="0" html>
<map name="Protocols">
<area shape="Poly" coords="74,0,113,29,98,72,52,72,38,27" href="https://www.manageengine.com/network-monitoring/what-is-snmp.html%22" alt="SNMP Tutorial" target="_blank">
<area shape="rect" coords="22,83,126,125" alt="FTP Tutorial" href="https://www.techtarget.com/searchnetworking/definition/File-Transfer-Protocol-FTP" target="_blank">
<area shape="circle" coords="73,168,32" alt="http Tutorial" href="https://www.webopedia.com/TERM/H/HTTP.html" target="_blank">
</map>

登入後複製

Explanation of the above program: In this example, we have created an image map using the image file called new.png, which has three clickable areas declared within it using the tag. The first clickable area is a polygonal shape that links to the SNMP page called www.managengine.com. The second clickable area is a rectangular shape that links to the FTP page called www.searchnetworking.com, and finally, the last clickable area is a circle that links to an HTTP page called www.webopedia.com.

Output:

HTML 中的區域標記

Output:

HTML 中的區域標記

Conclusion

Therefore, we have seen how the area tag is used in active areas in switching to the pages with brief information explaining how to use the tag in clickable areas with syntax and demo examples.

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

來源:php
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!