HTML 錨點


html錨點

基本概念

元素 (或HTML錨元素, Anchor Element)通常用來表示一個錨點/鏈接。但嚴格來說,元素不是一個鏈接,而是超文本錨點,可以鏈接到一個新文件、用id屬性指向任何元素。如果沒有元素沒有href屬性的話,可以作為原本鏈接位置的占位符,常用於home鏈接

注意:任何文檔流內容都可以被嵌套,只要不是交互內容類別(如按鈕、鏈接等)

標簽屬性

href

href屬性表示地址,共包括以下3種:

  1. 鏈接地址
<a href="http://www.baidu.com">百度</a>
  1. 下載地址
<a href="test.zip">下載測試</a>
  1. 錨點

    (1)href:#id名

    <a href="#test">目錄</a> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <div id="test" style="height: 200px;width: 200px; border: 1px solid black;margin-bottom: 300px;">內容</div>

    (2)href:頁面地址#id名

    <a href="http://baike.baidu.com/view/2202.htm#2">足球比賽規則</a>

href與src的區別

  href(hypertext reference)指超文本引用,表示當前頁面引用了別處的內容

  src(source)表示來源地址,表示把別處的內容引入到當前頁面

  所以<img><script><iframe>等應該使用src,而<link>應該使用href

  注意:href屬性一定不要留空,若暫時不需要寫地址,則寫#javascript:;。若href留空,會刷新頁面

4、手機號碼

  在移動端,使用<a href="tel:15012345678>15012345678可以喚出手機撥號盤

target

 target屬性表示鏈接打開方式

  1、_self  當前窗口(默認)

  2、_blank  新窗口

  3、_parent  父框架集

  4、_top  整個窗口

  5、_framename  指定框架

//外層框架
<frameset cols = "20%, *"> <frame src="left.html"> <frame src="right.html"> </frameset> //里層框架 <frameset rows = "50%,*"> <frame src="top.html"> <frame src="bottom.html" name="bottom"> </frameset> //錨點頁 <ul class="list"> <li class="in"><a href="chap1.html" target="_self">chap1(_self)</a></li> <li class="in"><a href="chap2.html" target="_blank">chap2(_blank)</a></li> <li class="in"><a href="chap3.html" target="_parent">chap3(_parent)</a></li> <li class="in"><a href="chap4.html" target="_top">chap4(_top)</a></li> <li class="in"><a href="chap5.html" target="bottom">chap5(framename)</a></li> </ul>

download

 download屬性用來設置下載文件的名稱(firefox/chrome/opera支持)

<a href="test.zip" download="gogo">test</a>

rel

rel屬性表示表示鏈接間的關系

alternate   相較於當前文檔可替換的呈現
author      鏈接到當前文檔或文章的作者
bookmark    鏈接最近的父級區塊的永久鏈接
help 與當前上下文相關的幫助鏈接 license 當前文檔的許可證 next 后一篇文檔 prev 前一篇文檔 nofollow 當前文檔的原始作者不推薦超鏈接指向的文檔 noreferer 訪問時鏈接時不發送referer字段 prefetch 預加載鏈接指向的頁面(對於chrome使用prerender) search 用於搜索當前文檔或相關文檔的資源 tag 給當前文檔打上標簽

  【應用】當一篇篇幅很長的文章需要多頁顯示時,配合next或prev可以實現前后頁面導航的預加載

<a href="prev.html" rel="prev prefetch prerender">前一頁</a> <a href="next.html" rel="next prefetch prerender">后一頁</a> //當然prefetch也可以用於預加載其他類型的資源 <link rel="prefetch prerender" href="test.img">

注意事項

 1、標簽的文本顏色只能自身進行設置,從父級繼承不到

  2、標簽的下划線顏色跟隨文本顏色進行變化

  3、標簽不可嵌套標簽

<div style="color: red;"> <a href="#">[1]從父級繼承不到紅色字體</a> <br> <a href="#" style="color: green">[2]下划線顏色與文本同色</a> <br> <a href="#">前面<a href="#">[3]a標簽不可嵌套</a></a> </div>

引用自https://www.cnblogs.com/liujunhang/p/10667162.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM