← 第 1 关 – 建造者

第 4/12 课 ⏱ 25 分钟

链接和第二个页面

你的网站不再只是一页了。你会再建一个页面,并用链接把它们连起来。

跟我看:链接

链接——可以点击、带你去别的地方的东西——用 <a> 标签制作:

<!-- A link to another page on your own website -->
<a href="lunch-menu.html">Lunch Menu</a>

<!-- A link out to somewhere else on the internet -->
<a href="https://www.si.edu">Our favorite museum's website</a>

第二个页面

你的网站目前只有 index.html。我们来添加第二个页面——就是同一文件夹里的另一个文件:

  1. 在 VS Code 里新建一个文件。根据你的项目命名,比如 lunch-menu.html、about-me.html、trips.html 或 roster.html。同样,小写,不要空格或重音符号。

  2. 粘贴完整的页面骨架(和第 1 课一样),写上自己的 <title>、<h1> 和一些内容。

  3. 用链接连接两个页面:在 index.html 上添加指向新页面的链接,在新页面上添加返回链接——比如 <a href="index.html">Back home</a>。

轮到你了 💪

创建第二个页面,把两个页面互相链接。至少有一个链接指向互联网上的某个地方。

🏫 学校网站——参考答案(lunch-menu.html)
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Lunch Menu – Riverside Elementary</title>
  </head>
  <body>
    <h1>This Week's Lunch Menu</h1>
    <ul>
      <li>Monday: tomato soup with pasta</li>
      <li>Tuesday: chicken with rice</li>
      <li>Wednesday: pancakes with syrup 🎉</li>
      <li>Thursday: beef stew with dumplings</li>
      <li>Friday: fish and potatoes</li>
    </ul>
    <p><a href="index.html">← Back to the homepage</a></p>
  </body>
</html>

在 index.html 上添加:

<p><a href="lunch-menu.html">Check out the lunch menu</a></p>
🙋 个人网站——参考答案(about-me.html)
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>More About Me – Jake</title>
  </head>
  <body>
    <h1>More About Me</h1>
    <p>I'm in 4th grade, I have a dog named Rocky, and I collect soccer cards.</p>
    <p>My favorite thing to listen to is <a href="https://www.youtube.com">music on YouTube</a>.</p>
    <p><a href="index.html">← Back home</a></p>
  </body>
</html>
🌍 旅行日记——参考答案(trips.html)
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>All Trips – Where We've Been</title>
  </head>
  <body>
    <h1>All Our Trips</h1>
    <ol>
      <li>The mountains – a ridge hike</li>
      <li>Greece – island hopping</li>
      <li>Washington, D.C. – museums and monuments</li>
    </ol>
    <p>We plan our routes with <a href="https://maps.google.com">Google Maps</a>.</p>
    <p><a href="index.html">← Back to the homepage</a></p>
  </body>
</html>
⚽ 俱乐部网站——参考答案(roster.html)
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Roster – Riverside Eagles FC</title>
  </head>
  <body>
    <h1>Team Roster</h1>
    <ul>
      <li>Jake – goalkeeper (captain)</li>
      <li>Matt – defense</li>
      <li>Owen – midfield</li>
      <li>Tom – forward</li>
    </ul>
    <p>Check the league schedule at <a href="https://www.ussoccer.com">ussoccer.com</a>.</p>
    <p><a href="index.html">← Back to the homepage</a></p>
  </body>
</html>
✅

检查一下: 你在首页点击链接 → 第二个页面打开了。你点击”返回” → 又回到首页。你的网站第一次有了不止一个页面!

这堂课你要记住