我有以下HTML:
<div class="captionBottom">
<a href="mp.aspx" title=""><img src="c.jpg" alt="" /></a>
<figcaption>View!</figcaption>
</div>
悬停时图像上会显示figcaption
。
如何将该链接指向锚标记的href
,因此点击figcaption
也会将用户带到mp.aspx
CSS:
figcaption {
width: 100%;
position: absolute;
background: #e55302;
background: rgba(229,83,2,0.90);
color: #FFF;
padding: 10px 0;
opacity: 0;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
cursor: pointer;
}
.captionBottom:hover figcaption {
opacity: 1;
cursor: pointer;
}
答案 0 :(得分:2)
<a href="mp.aspx" title="">
<img src="c.jpg" alt="" />
<figcaption>View!</figcaption>
</a>
答案 1 :(得分:2)
使用jQuery:
$('figcaption').on('click',function()
{
var figHref = $(this).prev().attr('href');
window.location.href = figHref; //changed the code.
});