
近来,将锚点放置在响应式图像上的正确位置变得更加重要。因为我们在日常生活中会遇到很多广告,如果锚点没有正确放置在响应式图像下方,将会使用户更难以理解该网页。
我们使用 CSS 和 HTML 将元素锚定到响应图像上的正确位置。在我们深入本文以更好地理解之前,让我们快速浏览一下 HTML 中的锚点和图像标签。
通过其 href 属性,HTML 元素 <a>(或锚元素)生成指向网页、文件、电子邮件地址、同一页面上的位置或可以通过 URL 寻址的任何其他内容的超链接。
每个 <a> 应包含描述链接最终目的地的文本。当焦点位于 <a> 元素时,按 Enter 键将激活 href 属性(如果存在)。
以下是 HTML 中锚标记的语法
<a href = "link"> Link Name </a>
要在网页或网站中插入图像,请使用 HTML <img> 标记。在现代网站中,图像使用 <img> 元素链接到网页,该元素包含图像的空间。这可以防止网站直接向网页添加图像。
以下是img标签的语法
<img src="" alt="" width="" height="">
要了解有关将元素锚定到响应式图像上正确位置的更多信息,请查看以下示例
在下面,我们使用 CSS 将元素锚定到响应图像上的正确位置。
<!DOCTYPE html>
<html>
<body>
<style>
.tutorial {
display: flex;
width: 60%;
margin: auto;
}
.type {
text-align: center;
}
.tutorial img {
max-width: 90%;
display: block;
}
</style>
<div class="tutorial">
<div class="type">
<img src="https://www.tutorialspoint.com/java/images/java-mini-logo.jpg">
<a href="https://www.tutorialspoint.com/java/index.htm">Java Tutorial</a>
</div>
<div class="type">
<img src="https://www.tutorialspoint.com/html/images/html-mini-logo.jpg">
<a href="https://www.tutorialspoint.com/html/index.htm">HTML Tutorial</a>
</div>
</div>
</body>
</html>执行脚本时,它将生成一个输出,其中包含上传到网页上的图像以及附加在响应图像底部的相应超链接。
考虑以下示例,我们将元素的锚点放置在响应式图像上的正确位置。
<!DOCTYPE html>
<html>
<body>
<style>
#tutorial{
float:left;
position: relative;
}
#tutorial img {
max-width: 100%;
display: inline-block;
}
a.link1{
height:15%;
width:15%;
position: absolute;
top:60%; left:10%;
display:block;
background:#00FF00 ;
}
a.link2{
height:15%;
width:15%;
position: absolute;
top:50%;
left:76%;
display: block;
background:#FF0000;
}
</style>
<div id="tutorial">
<div>
<img src="https://www.math-english.com/media/dices/two-dices2.png">
</div>
<a href="https://www.tutorialspoint.com/html/index.htm" class="link1">HTML</a>
<a href="https://www.tutorialspoint.com/java/index.htm" class="link2">JAVA</a>
</div>
</body>
</html>运行上述脚本时,将弹出输出窗口,显示网页上上传的图像以及附加在图像两侧的超链接,并在超链接中应用了 CSS。
以上就是如何将元素锚定到响应式图像的正确位置?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号