超链接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.mzph.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) 复制…