参考资料

  1. cache-control 浏览器缓存行为
  2. HTML 书签属性格式化
  3. HTML 图像
  4. Html转ASP/Perl有哪些
  5. HTML 注释
  6. HTML 折行
  7. HTML 提示
  8. HTML 删除字符效果和插入字符效果

HTML 超链接

基本标签

<a> 标签用于创建超链接

主要属性

  • href: 指定链接目标URL

  • target: 控制链接打开方式

    • _self: 当前窗口(默认)

    • _blank: 新窗口

    • _parent: 父框架

    • _top: 顶层框架

  • rel: 定义链接与当前文档的关系

    • nofollow: 告诉搜索引擎不要追踪

    • noopener: 防止新窗口访问原窗口

    • noreferrer: 隐藏来源信息

基本用法

<a href="https://example.com">示例链接</a>
<a href="page.html" target="_blank">新窗口打开</a>
<a href="#section-id">页面锚点</a>

功能扩展

  1. 邮件链接

<a href="mailto:contact@example.com">发送邮件</a>
  1. 电话链接

<a href="tel:+1234567890">拨打电话</a>
  1. 下载链接

<a href="file.pdf" download>下载PDF</a>

CSS 扩展样式

/* 基础样式 */
a {
  color: #0066cc;
  text-decoration: none;
}

/* 悬停效果 */
a:hover {
  text-decoration: underline;
  color: #004499;
}

/* 访问过的链接 */
a:visited {
  color: #660099;
}

/* 活动状态(点击时) */
a:active {
  color: #cc0000;
}

/* 按钮样式链接 */
a.button {
  display: inline-block;
  padding: 10px 15px;
  background-color: #0066cc;
  color: white;
  border-radius: 4px;
  transition: background-color 0.3s;
}

a.button:hover {
  background-color: #004499;
}

高级用法

  1. 链接预加载

<link rel="prefetch" href="page.html">
  1. 链接预连接

<link rel="preconnect" href="https://example.com">
  1. 链接预加载资源

<link rel="preload" href="font.woff2" as="font">