简体   繁体   English

如何链接到已在 HTML/CSS 中链接的图像

[英]How to put a link to an image already linked in HTML/CSS

I was trying to create a similar Apple site to learn HTML & CSS, and I stopped when I couldn't figure out how to put a link on an image that already has a link itself, I will post here the "code" hoping someone can help me...我试图创建一个类似的 Apple 网站来学习 HTML 和 CSS,当我不知道如何在已经有链接的图像上放置链接时我就停了下来,我会在这里发布“代码”希望有人可以帮我...

 <a href="https://apple.com/iphone-14"> <div class="hero" style="background-image: url(Images/iPhone_14-HERO-SMALL.jpg); margin-top: -15mm"> <header class="titleText"> <div style="color: #1D1D1E; font-family: SF-Pro-Bold;">iPhone 14</div> <div style="color: #1D1D1E; font-size: 7.5mm;">Big and bigger.</div> <span style="color: black"><a href ="https://apple.com/iphone-14">Learn more ></a></span> <!-- This is the part that deletes the whole link image --> </header> </div> </a>

First of all you should attend that using a block-level element like div or the worse than that header element!首先,您应该注意使用像div这样的块级元素或比header元素更糟糕的元素! in an inline-level element like a is not html5 standard then according to your DOM you are wrapping a link inside another one: So it is better to write your DOM something like example below:在像a这样的内联级元素中,不是 html5 标准然后根据您的 DOM,您将链接包装在另一个元素中:因此最好将您的 DOM 编写如下示例:

<a class = "hero" style = "background-image: url(Images/iPhone_14-HERO-SMALL.jpg); margin-top: -15mm">
   <span style = "color: #1D1D1E; font-family: SF-Pro-Bold;">iPhone 14</span>
   <span style = "color: #1D1D1E; font-size: 7.5mm;">Big and bigger.</span>
<a href ="https://apple.com/iphone-14" style = "color: black; position: relative; z-index: 2">Learn more ></a>
</a>

and if you wanna have a block level element so style display: block to your inner spans如果你想要一个块级元素,那么样式显示:块到你的内部跨度

<a href="https://www.apple.com/iphone-14/"><img src="image-link-here" alt=""></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM