属性付きのリンクと画像を追加する
このステップでは、画像とハイパーリンクを追加して、ページをより動的にします。
<img>: 画像タグは、画像を埋め込むために使用されます。これは自己終了タグであり、2 つの必須属性が必要です。
src: 画像ファイルへのパスを指定します。
alt: 画像の代替テキストを提供します。これはアクセシビリティや、画像が表示できない場合に重要です。
<a>: アンカータグは、ハイパーリンクを作成するために使用されます。href 属性は、リンク先の URL を指定します。
まず、プロフィール写真を追加しましょう。セットアップスクリプトは、すでに images/profile.png にプレースホルダー画像を配置しています。<h1> タグのすぐ下に <img> タグを追加してください。
次に、GitHub プロフィールのようないくつかの外部サイトへのリンクを追加しましょう。これは新しい「Find Me Online」セクションに配置します。スキルリストの下に以下のコードを追加してください。
<!-- Add this img tag below the h1 tag -->
<img src="images/profile.png" alt="A placeholder profile picture" />
<!-- Add this new section below the skills list -->
<h2>Find Me Online</h2>
<p>
You can find my work on
<a href="https://github.com/labex-labs" target="_blank">GitHub</a>.
</p>
リンクの target="_blank" 属性は、ブラウザにリンクを新しいタブで開くように指示します。
これで、index.html ファイルの <body> は次のように構造化されます。
<body>
<div class="container">
<h1>John Doe</h1>
<img src="images/profile.png" alt="A placeholder profile picture" />
<p>
Welcome to my personal webpage! I am a passionate web developer learning
the fundamentals of HTML. I enjoy creating clean and efficient code to
build beautiful and functional websites.
</p>
<h2>My Skills</h2>
<ul>
<li>HTML & CSS</li>
<li>JavaScript</li>
<li>Python</li>
<li>Problem Solving</li>
</ul>
<h2>Find Me Online</h2>
<p>
You can find my work on
<a href="https://github.com/labex-labs" target="_blank">GitHub</a>.
</p>
</div>
</body>
ファイルを保存し、Web 8080 タブを更新してください。プロフィール画像とクリック可能なリンクが表示されます。