HTML 学习笔记(五)超链接

HYperText 超文是用超链接的方式,将不同空间的文字信息组合在一起的网状文其就像一个桥梁,建立了不同页面中的联系,实现了访问不同网站中页面的功能

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <!--"a"是anchor的缩写,意为"锚","href"属性是HypertText Reference的缩写,意为超文本引用
        其值为"目标页面的地址"与图片的"src"属性类似-->
        <a href="https://mks.hzau.edu.cn/__local/B/DD/8A/CFE1BE51C922D4EEE6542F91825_3CC5AB02_6115BC.pdf?e=.pdf">毛选</a>
        <a href="https://www.marxists.org/chinese/marx/capital/index.htm">资本论</a>
        <!--上述这种打开方式,实在原有页面的基础上打开的,如何使其在新窗口中打开呢?-->
        <!--"target"属性可以定义超链接页面的打开方式"_self"代表在当前页面打开,"_blank"代表在空白页面打开-->
        <a href="https://mks.hzau.edu.cn/__local/B/DD/8A/CFE1BE51C922D4EEE6542F91825_3CC5AB02_6115BC.pdf?e=.pdf" target="_self">毛选</a>
        <a href="https://www.marxists.org/chinese/marx/capital/index.htm" target="_blank">资本论</a>
        
        <!--另外两种属性目前还未用到,其相关解释可参考以下-->
        <a href="https://blog.csdn.net/qq_41666142/article/details/116723198">说说超链接 target 属性的取值和作用?</a>
    </body>
</html>

锚点链接是网页超链接中的一种,其就像一个迅速定位器,用来实现同一个页面中不同区域的跳转
实现其需要两个定义,1.跳转目标的定义 2.锚点的定义
1.跳转目标的定义

html 复制代码
<!--在跳转目标的位置处天机一个id属性和其属性值,该属性值即为锚点的名字(id的属性值不能和其他锚点同名)-->
<p id="box1"></p>
<p id="box2"></p>

2.锚点的定义

html 复制代码
<a href="#box1">目标一</a>
<a href="#box2">目标二</a>

完整代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <h1 align="center">一些图片</h1>
        <p align="center" id="top_">
            <a href="#box1">狗头</a>
            <a href="#box2">Lucia</a>
            <a href="#box3">彼岸花</a>
        </p>

        <p align="center" id="box1">
            <img src="dog1.jpg" alt="dog1" title="狗头保命">
            <a href="#top_">回到顶部</a>
        </p>
        <p align="center" id="box2">
            <img src="../../pic/Lucia.png" alt="Lucia" width="1080" height="720" title="Red lotus">
            <a href="#top_">回到顶部</a>
        </p>
        <p align="center" id="box3">
            <img src="https://img.zcool.cn/community/0162305dc57ebda801209e1f041f61.jpg@1280w_1l_2o_100sh.jpg" alt="曼珠沙华" title="石蒜">
            <a href="#top_">回到顶部</a>
        </p>
    </body>
</html>

可以通过点击来移动到网页的指定位置:

还可以加入一个返回顶部的标签:

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <h1 align="center">一些图片</h1>
        <p align="center" id="top_">
            <a href="#box1">狗头</a>
            <a href="#box2">Lucia</a>
            <a href="#box3">彼岸花</a>
        </p>

        <p align="center" id="box1">
            <img src="dog1.jpg" alt="dog1" title="狗头保命"><br>
            <a href="#top_">回到顶部</a>
        </p>
        <p align="center" id="box2">
            <img src="../../pic/Lucia.png" alt="Lucia" width="1080" height="720" title="Red lotus"><br>
            <a href="#top_">回到顶部</a>
        </p>
        <p align="center" id="box3">
            <img src="https://img.zcool.cn/community/0162305dc57ebda801209e1f041f61.jpg@1280w_1l_2o_100sh.jpg" alt="曼珠沙华" title="石蒜">
            <br>
            <a href="#top_">回到顶部</a>
        </p>
    </body>
</html>
相关推荐
问心无愧05133 分钟前
[极客大挑战 2019]HardSQL
笔记
m0_646429974 分钟前
BCrypt 与 JWT 认证流程学习笔记
笔记·学习
apple_692658858 分钟前
QX 效率启动器安装包:开源生产力工具,快捷键统一入口Raycast免费开源平替版来啦
学习·开源·办公
一直C29 分钟前
嵌入式 Linux 驱动开发学习笔记:中断、等待队列与工作队列
linux·驱动开发·嵌入式硬件·学习·imx6ull
问心无愧051342 分钟前
[GXYCTF2019]BabyUpload
笔记
我命由我1234543 分钟前
5-2.Python 编码进阶 - 字符串进阶(拼接、普通格式化、普通格式化数字精度控制、快速格式化、遍历、常用方法)
java·开发语言·后端·python·学习·java-ee·学习方法
http阿拉丁神猫5 小时前
Go语言入门笔记:从基础到开发环境搭建(二)
开发语言·笔记·golang
java1234_小锋6 小时前
【技术专题】HTML5 网页技术 - HTML5 Canvas 基础以及动画入门
前端·html·html5
HRBorderInsight8 小时前
马来西亚人均收入一个月多少钱,个人薪资和家庭收入要分开看
经验分享·笔记
又見山10 小时前
本地 Markdown 与数据主权:你的笔记到底属于谁
笔记·obsidian