これで、index.htmlファイルの body は以下のようになります。最初のセクション内に新しいリンクがあることに注意してください。
<body>
<h1>Welcome to the HTML Links Lab</h1>
<p>
This page will be used to practice creating different kinds of HTML links.
</p>
<nav>
<!-- Navigation links will be added here -->
</nav>
<div class="section">
<h2>Section 1</h2>
<p>
<a href="https://labex.io">Visit LabEx</a>
</p>
</div>
<div class="section">
<h2>Section 2</h2>
<p>
This is the section we will link to from the top of the page. It is placed
far down to demonstrate the page jump effect.
</p>
</div>
</body>
id属性は、ページ上の HTML 要素に一意の識別子を提供します。idの値は、HTML ドキュメント内で一意でなければなりません。私たちの内部リンクhref="#section2"は、id="section2"を持つ要素を探します。
Section 2 の<h2>タグにこのidを追加しましょう。以下の行を見つけます。
<h2>Section 2</h2>
そして、id属性を含めるように変更します。
<h2 id="section2">Section 2</h2>
更新されたindex.htmlファイルの 2 番目のセクションは、以下のようになります。
<div class="section">
<h2 id="section2">Section 2</h2>
<p>
This is the section we will link to from the top of the page. It is placed
far down to demonstrate the page jump effect.
</p>
</div>
ファイルを保存し、「Web 8080」タブに戻ります。ページ上部にある「Jump to Section 2」リンクをクリックします。ブラウザは「Section 2」の見出しまでスムーズにスクロールするはずです。