超鏈接href屬性_如何使用標簽上的HREF屬性制作HTML超鏈接

超鏈接href屬性

A website is a collection of web pages. And these pages need to be linked or connected by something. And to do so, we need to use a tag provided by HTML: the a tag.

網站是網頁的集合。 這些頁面需要通過某種方式鏈接或連接。 為此,我們需要使用HTML提供的標簽: a標簽。

This tag defines a hyperlink, which is used to link from one page to another. And the most important attribute of the a element is the href attribute, which indicates the link's destination.

此標記定義超鏈接,用于將一個頁面鏈接到另一頁面。 a元素最重要的屬性是href屬性,它指示鏈接的目的地。

In this guide, I will show you how to make HTML hyperlinks using the href attribute on the a tag.

在本指南中,我將向您展示如何使用a標簽上的href屬性制作HTML超鏈接。

  • What is a link?

    什么是鏈接?

  • How to create internal links

    如何創建內部鏈接

  • Browse to pages on the same level

    瀏覽到相同級別的頁面

  • Browse to pages located on another folder

    瀏覽到另一個文件夾上的頁面

  • Browse from a page located in a folder to the root

    從文件夾中的頁面瀏覽到根目錄

  • How to create external links

    如何創建外部鏈接

  • How to create anchor links

    如何創建錨鏈接

  • Navigate on the same page

    在同一頁面上導航

  • Navigate on another page

    導航到另一頁

  • Conclusion

    結論

A link is clickable text that allows you to browse from one page to another, or to a different part of the same page.

鏈接是可單擊的文本,使您可以從一個頁面瀏覽到另一頁面或同一頁面的不同部分。

In web development, there are several ways to create links, but the most common is by using the a tag and the href attribute. This last is where we specify the destination address of the link.

在Web開發中,有幾種創建鏈接的方法,但是最常見的方法是使用a標簽和href屬性。 最后一點是我們指定鏈接的目標地址的位置。

The a tag helps us create three main kinds of links: an internal link, an external link, and an anchor link. That said, we can now dive into how to create an internal link in the next section.

a標簽將幫助我們建立三種主要類型的鏈接:內部鏈接,外部鏈接,錨鏈接。 也就是說,我們現在可以在下一部分中深入探討如何創建內部鏈接。

When it comes to building a website, it makes sense to have a connection between pages. And as long as these links allow us to navigate from page A to page B, it's called an internal link (since it's always in the same domain name or on the same website). So, an internal link is a link that allows navigating to another page on a website.

建立網站時,在頁面之間建立聯系是有意義的。 只要這些鏈接允許我們從A頁導航到B頁,它就稱為內部鏈接(因為它始終位于相同的域名或相同的網站中)。 因此,內部鏈接是允許導航到網站上另一個頁面的鏈接。

Now, considering our folder is structured as follows:

現在,考慮我們的文件夾結構如下:

├── folder1
|  └── page2.html
├── page1.html
├── index.html

Here we have three use cases, and for each, we will create an example.

這里有三個用例,每個用例都將創建一個示例。

瀏覽到相同級別的頁面 (Browse to pages on the same level)

  • index.html

    index.html

<a href="page1.html">Browse to Page 1</a>

As you can see, the page page1.html is on the same level, therefore the path of the href attribute is just the name of the page.

如您所見,頁面page1.html處于同一級別,因此href屬性的路徑僅是頁面的名稱。

瀏覽到另一個文件夾中的頁面 (Browse to pages located in another folder)

  • page1.html

    page1.html

<a href="./folder1/page2.html">Browse to Page 2</a>

Here, we have a different use case since the page we want to visit is now not on the same level. And to be able to navigate to that page, we should specify the complete path of the file including the folder.

這里,我們有一個不同的用例,因為我們要訪問的頁面現在不在同一級別。 為了能夠導航到該頁面,我們應該指定文件的完整路徑,包括文件夾。

Great! Let's now dive into the last use case.

大! 現在讓我們進入最后一個用例。

從文件夾中的頁面瀏覽到根目錄 (Browse from a page located in a folder to the root)

  • page2.html

    page2.html

<a href="../index.html">Browse to the Home Page</a>

Now, here to navigate to the index.html page, we should first go one level up before being able to browse to that page.

現在,在這里導航到index.html頁面,我們應該先上一層然后才能瀏覽到該頁面。

We have now covered internal links, so let's move on and introduce how to navigate to external links.

現在我們已經介紹了內部鏈接,因此讓我們繼續并介紹如何導航到外部鏈接。

It's always useful to have the ability to navigate to external websites as well.

能夠導航到外部網站總是很有用的。

<a href="https://www.google.com/">Browse to Google</a>

As you can see here, to navigate to Google, we have to specify its URL to the href attribute.

如您所見,要導航到Google,我們必須將其URL指定給href屬性。

External and internal links are used to navigate from page A to page B. However, sometimes we want to stay on the same page and navigate to a specific part. And to do so, we have to use something called anchor link, let's dive into it in the next section.

外部和內部鏈接用于從頁面A導航到頁面B。但是,有時我們希望停留在同一頁面上并導航到特定部分。 為此,我們必須使用一種稱為錨鏈接的工具,讓我們在下一部分中進行深入研究。

An anchor link is a bit more specific: it allows us to navigate from point A to point B while remaining on the same page. It can also be used to go to a part on another page.

錨點鏈接更具體:它使我們可以從A點導航到B點,同時保持在同一頁面上。 它也可以用于轉到另一頁上的零件。

<a href="#about">Go to the anchor</a>
<h1 id="about"></h1>

Compared to the others, this one is a bit different. Indeed it is, but it still works the same way.

與其他相比,這有點不同。 確實如此,但是它仍然以相同的方式工作。

Here, instead of a page link, we have a reference to an element. When we click on the link, it will look for an element with the same name without the hashtag (about). If it finds that id, it browses to that part.

在這里,我們有一個元素的引用,而不是頁面鏈接。 當我們單擊鏈接時,它將查找沒有井號( about )的同名元素。 如果找到該ID,則會瀏覽到該部分。

<a href="page1.html#about">Go to the anchor</a>

This is pretty the same as the previous example, except that we have to define the page in which we want to browse and add the anchor to it.

除了必須定義要瀏覽的頁面并向其添加錨點之外,這與前面的示例幾乎相同。

結論 (Conclusion)

The href is the most important attribute of the a tag. It allows us to navigate between pages or just a specific part of a page. Hopefully, this guide will help you build a website with plenty of links.

hrefa標簽最重要的屬性。 它使我們可以在頁面之間或頁面的特定部分之間導航。 希望本指南將幫助您建立一個包含大量鏈接的網站。

Thanks for reading.

謝謝閱讀。

Feel free to reach out to me!

歡迎與我聯系!

TWITTER ? BLOG ?NEWSLETTER ?GITHUB ?LINKEDIN ?CODEPEN ?DEV

TWITTER BLOG 消息 GitHub的 LinkedIn CODEPEN DEV

Photo by JJ Ying on Unsplash

圖片由JJ Ying在Unsplash上拍攝

翻譯自: https://www.freecodecamp.org/news/how-to-make-html-hyperlinks-using-the-href-attribute-on-tags/

超鏈接href屬性

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390495.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390495.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390495.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

劍指 Offer 42. 連續子數組的最大和

輸入一個整型數組&#xff0c;數組中的一個或連續多個整數組成一個子數組。求所有子數組的和的最大值。 要求時間復雜度為O(n)。 示例1: 輸入: nums [-2,1,-3,4,-1,2,1,-5,4] 輸出: 6 解釋: 連續子數組 [4,-1,2,1] 的和最大&#xff0c;為 6。 解題思路 對于一個數組&…

centos 7安裝配置vsftpd

yum install -y vsftpd #安裝vsftpd yum install -y psmisc net-tools systemd-devel libdb-devel perl-DBI #安裝vsftpd虛擬用戶配置依賴包 systemctl enable vsftpd.service #設置vsftpd開機啟動 cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak #備份默認配置文…

amazeui學習筆記--css(基本樣式3)--文字排版Typography

amazeui學習筆記--css&#xff08;基本樣式3&#xff09;--文字排版Typography 一、總結 1、字體&#xff1a;amaze默認非 襯線字體&#xff08;sans-serif&#xff09; 2、引用塊blockquote和定義列表&#xff1a;引用塊blockquote和定義列表&#xff08;dl dt&#xff09;注意…

劍指 Offer 46. 把數字翻譯成字符串

給定一個數字&#xff0c;我們按照如下規則把它翻譯為字符串&#xff1a;0 翻譯成 “a” &#xff0c;1 翻譯成 “b”&#xff0c;……&#xff0c;11 翻譯成 “l”&#xff0c;……&#xff0c;25 翻譯成 “z”。一個數字可能有多個翻譯。請編程實現一個函數&#xff0c;用來計…

Zend?Guard?7?,?Zend?Guard?Loader處理PHP加密

環境&#xff1a;使用Zend Guard 7 軟件加密。 PHP 5.6 LNMP 一鍵安裝&#xff0c;PHP5.6Zend Guard Loader &#xff08;對應的版本文件&#xff09;是已經安裝好了&#xff0c;還要安裝 opcache.so ,直接在lnmp 安裝教程中有。因為自動安裝 的 版本并不對應&#xff0c;于…

qr碼是二維碼碼_如何使用QR碼進行有效的營銷和推廣

qr碼是二維碼碼Efficient means doing things right. Effective is about doing the right things.高效意味著做正確的事。 有效就是做正確的事。 I am an advocate for efficiency and effectiveness. There must be a more efficient way to share contact details other th…

ELK學習記錄三 :elasticsearch、logstash及kibana的安裝與配置(windows)

注意事項&#xff1a; 1.ELK版本要求5.X以上 2.Elasticsearch5.x版本必須基于jdk1.8&#xff0c;安裝環境必須使用jdk1.8 3.操作系統windows10作為測試環境&#xff0c;其他環境命令有差異&#xff0c;請注意 4.本教程適合完全離線安裝 5.windows版本ELK安裝包下載路徑&#xf…

【quickhybrid】JSBridge的實現

前言 本文介紹quick hybrid框架的核心JSBridge的實現 由于在最新版本中&#xff0c;已經沒有考慮iOS7等低版本&#xff0c;因此在選用方案時沒有采用url scheme方式&#xff0c;而是直接基于WKWebView實現 交互原理 具體H5和Native的交互原理可以參考前文的H5和Native交互原理 …

mongodb atlas_如何使用MongoDB Atlas將MERN應用程序部署到Heroku

mongodb atlas簡介 (Introduction to MERN) In this article, well be building and deploying an application built with the MERN stack to Heroku.在本文中&#xff0c;我們將構建和部署使用MERN堆棧構建的應用程序到Heroku。 MERN, which stands for MongoDB, Express, R…

面試題 10.02. 變位詞組

編寫一種方法&#xff0c;對字符串數組進行排序&#xff0c;將所有變位詞組合在一起。變位詞是指字母相同&#xff0c;但排列不同的字符串。 注意&#xff1a;本題相對原題稍作修改 示例: 輸入: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], 輸出: [ [“ate”,…

智能合約設計模式

2019獨角獸企業重金招聘Python工程師標準>>> 設計模式是許多開發場景中的首選解決方案&#xff0c;本文將介紹五種經典的智能合約設計模式并給出以太坊solidity實現代碼&#xff1a;自毀合約、工廠合約、名稱注冊表、映射表迭代器和提款模式。 1、自毀合約 合約自毀…

如何使用1Password,Authy和Privacy.com外包您的在線安全性

Take some work off your plate while beefing up security with three changes you can make today.通過今天可以進行的三項更改來增強安全性&#xff0c;同時省下一些工作。 Unstable times are insecure times, and we’ve already got enough going on to deal with. When…

「CodePlus 2017 12 月賽」火鍋盛宴

n<100000種食物&#xff0c;給每個食物煮熟時間&#xff0c;有q<500000個操作&#xff1a;在某時刻插入某個食物&#xff1b;查詢熟食中編號最小的并刪除之&#xff1b;查詢是否有編號為id的食物&#xff0c;如果有查詢是否有編號為id的熟食&#xff0c;如果有熟食刪除之…

5815. 扣分后的最大得分

給你一個 m x n 的整數矩陣 points &#xff08;下標從 0 開始&#xff09;。一開始你的得分為 0 &#xff0c;你想最大化從矩陣中得到的分數。 你的得分方式為&#xff1a;每一行 中選取一個格子&#xff0c;選中坐標為 (r, c) 的格子會給你的總得分 增加 points[r][c] 。 然…

您有一個上云錦囊尚未領取!

前期&#xff0c;我們通過文章《確認過眼神&#xff1f;上云之路需要遇上對的人&#xff01;》向大家詳細介紹了阿里云咨詢與設計場景下的五款專家服務產品&#xff0c;企業可以通過這些專家服務產品解決了上云前的痛點。那么&#xff0c;當完成上云前的可行性評估與方案設計后…

怎么從運營轉到前端開發_我如何在16個月內從銷售人員轉到前端開發人員

怎么從運營轉到前端開發On August 18, 2015, I was on a one-way flight headed to Copenhagen from Toronto Pearson Airport. I was starting my two semester exchange at the Copenhagen Business school. 2015年8月18日&#xff0c;我乘坐單程飛機從多倫多皮爾遜機場前往哥…

Python os.chdir() 方法

概述 os.chdir() 方法用于改變當前工作目錄到指定的路徑。 語法 chdir()方法語法格式如下&#xff1a; os.chdir(path) 參數 path -- 要切換到的新路徑。 返回值 如果允許訪問返回 True , 否則返回False。 實例 以下實例演示了 chdir() 方法的使用&#xff1a; #!/usr/bin/pyth…

oracle認證考試_Oracle云認證–通過此3小時免費課程通過考試

oracle認證考試This Oracle Cloud Certification exam will take – on average – about one week of study to prepare for. Most people who seriously commit to their studies are ready to pass the exam within about four days.這項Oracle Cloud認證考試平均需要大約一…

git 修改遠程倉庫源

自己已經寫好了一個項目&#xff0c;想上傳到 github github 創建新項目 新建 README.md &#xff0c; LICENSE 本地項目添加 github 遠程倉庫源 不是git項目git remote add origin https://USERNAME:PASSWORDgithub.com/USERNAME/pro.git已是git項目&#xff0c;先刪除再添加 …

Docker 常用命令備忘錄

build鏡像docker build -t"name" . 復制代碼后臺運行docker run -d -i -t 14a21c118315 /bin/bash 復制代碼刪除鏡像docker image rmi -f 300de37c15f9 復制代碼停止運行的鏡像docker ps docker kill (id) 復制代碼進入鏡像docker attach 29f2ab8e517c(ps id) 復制…