我是这一切的初学者,但我会尽力解释。
我使用 Stack Overflow 来弄清楚如何将一张图像放置在另一张图像之上。我这样做的原因是因为我希望在我的网站顶部有一个大栏,其中包含联系方式,其中一部分链接到电子邮件地址。
我使用了以下代码:
CSS:
.imgA1 {
position:absolute; top: 0px;
left: 0px; z-index: 1; } <br> .imgB1 {
position:absolute; top: 0px; left:
100px; z-index: 3;
}
HTML:
<img class=imgA1 src="images\headings\red_heading.jpg"><br>
<img class=imgB1 src="images\headings\red_heading_email.jpg">
请注意:我必须在 之间放置一个空格。和上面的 img 类,否则它不会显示我的代码!!
以上所有内容都运行得很好,但是我想添加一个电子邮件链接到上面的第二个类,所以当有人单击它时,电子邮件客户端会打开。
我希望这一切都是有道理的。
无论如何,帮助/建议都会很棒。
亲切的问候,
史蒂夫
我想做的是添加一个链接到上面的“imgB1”部分......
I'm a beginner at all this however i will do my best to explain.
I used Stack Overflow to figure out how to position an image on top of another one. My reason for this is because i want a large bar at the top of my website with contact details, with a part of it linking to an email address.
I used the following code:
CSS:
.imgA1 {
position:absolute; top: 0px;
left: 0px; z-index: 1; } <br> .imgB1 {
position:absolute; top: 0px; left:
100px; z-index: 3;
}
HTML:
<img class=imgA1 src="images\headings\red_heading.jpg"><br>
<img class=imgB1 src="images\headings\red_heading_email.jpg">
PLEASE NOTE: I've had to put a space between the < and the img class above or else it wont display my code!!
All the above works really well, however i want to add an email link to the second class above, so when someone clicks it an email client opens.
I hope all this makes sense.
Anyway help/advice would be fantastic.
Kind regards,
Steve
What i want to do is add a link to the "imgB1" section above...
发布评论
评论(7)
将您的
标记放在
(锚点)标记内,并使用锚点标记的
href
属性,将您的代码单击图像后打开用户的电子邮件客户端将如下所示。现在,单击图像将启动网站访问者默认邮件客户端,“发送至”邮件地址“[电子邮件受保护]”。
Place your
<img>
tags within<a>
(Anchor) tag, and with thehref
attribute of anchor tag, your code to open an email client of user upon click on image will look something like this.Now clicking on the image will launch site visitors default mail client with "to" the mail address "[email protected]".
我不确定我是否理解,但要添加到图像的链接,您只需将其放入 锚标记,要打开电子邮件客户端,您可以使用 mailto:[email protected]
您可能还需要向 imgB1 类添加 border: none,因为默认情况下,图像在超链接时具有边框。
I'm not sure that I understand, but to add a link to the image you would just need to put it inside an anchor tag, and to open an email client you would use an href of mailto:[email protected]
You may also need to add a border: none to the imgB1 class, as by default images have a border when they are hyperlinked.
我想你想要的是:
< img 类=imgA1 src="images\headings\red_heading.jpg">
< img src="images\headings\red_heading_email.jpg">
使用相同的CSS。这应该将定位应用于锚标记,该标记又包含您要覆盖的图像。
安迪
i think what you want is:
< img class=imgA1 src="images\headings\red_heading.jpg">
< img src="images\headings\red_heading_email.jpg">
with the same css. this should apply the positioning to the anchor tag, which in turn contains the image you want to overlay.
Andy
这很……奇怪……但是你可以用 Javascript 来做到这一点,例如在 JQuery 中你可以做这样的事情:
请注意,我还没有测试过它
it's quite... strange... but you can do that with Javascript, as example in JQuery you can do something like this:
Note that I've not tested it
如果由于图像上的位置变化而导致上述方法不起作用(不确定它们是否会),您可以将图像的“onclick”属性设置为如下函数:
If the approaches above don't work because of the positioning change on the image (not sure if they will or not), you can set the "onclick" property of the image to a function like this:
< img 类=imgA1 src="images\headings\red_heading.jpg">
< img class=imgB1 src="images\headings\red_heading_email.jpg">
您无法通过 CSS 类获得链接,因为 CSS 仅定义 DISPLAY/LAYOUT 属性。
您必须向 img 添加 html 锚标记。
< img class=imgA1 src="images\headings\red_heading.jpg">
< img class=imgB1 src="images\headings\red_heading_email.jpg">
You can't have a link through a CSS class because CSS only defines DISPLAY/LAYOUT properties.
You will have to add an html anchor tag to the img.
默认情况下,超链接的图像周围会有边框(通常为蓝色)。确保通过 css 或使用 IMG 属性 border="0" 删除它
By default, images that are hyperlinked will have a border around them (usually blue). Make sure to remove it via css or with the IMG attribute border="0"