添加带属性的链接和图片
在这个步骤中,你将通过添加图片和超链接来使你的页面更具动态性。
<img>:图片标签用于嵌入图片。它是一个自闭合标签,需要两个必需的属性:
src:指定图片文件的路径。
alt:为图片提供替代文本,这对于可访问性以及图片无法显示时非常重要。
<a>:锚点标签用于创建超链接。href 属性指定链接的目标 URL。
首先,让我们添加一张个人资料图片。设置脚本已经将一个占位符图片放在了 images/profile.png。在 <h1> 标签正下方添加 <img> 标签。
接下来,让我们添加一个指向外部网站的链接,例如 GitHub 个人资料。我们将把它放在一个新的“在线找到我”部分。在你的技能列表下方添加以下代码:
<!-- 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 标签页。你将看到个人资料图片和一个可点击的链接。