【发布时间】:2017-04-02 14:38:28
【问题描述】:
我的页面上有多个图像,我希望它们有一个黑色的覆盖层(如不透明度为 0.6 的黑色矩形),悬停会消失。这是最简单的部分。
.item {
position: relative;
width: 200px;
height: 200px;
}
.item img {
width: 100%;
vertical-align: top;
}
.item:after,
.item:before {
position: absolute;
opacity: 1;
transition: all 0.8s;
-webkit-transition: all 0.8s;
}
.item:after {
content: '\A';
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.6);
}
.item:before {
content: attr(data-content);
width: 100%;
color: #fff;
z-index: 1;
bottom: 1;
padding: 34px 6px;
text-align: center;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.item:hover:after,
.item:hover:before {
opacity: 0;
}
<div class="item" data-content="Image Title">
<a href="http://www.google.com">
<img src="http://placehold.it/180x267">
</a>
</div>
<div class="item" data-content="Second Image Title">
<a href="http://www.google.com">
<img src="http://placehold.it/180x267">
</a>
</div>
这里有一个 FIDDLE,覆盖在工作,但在移动设备上没有响应。
这是我的问题:我也希望将图像链接起来。这似乎与 :before :after 伪类不兼容。我试过替换
content: '\A';
与
{ content: ' [' attr(href) ']'; }
但没有运气。图像确实会变成链接,但它们不再具有叠加层。他们在移动设备上也没有响应我该如何解决这个问题?这是一个 FIDDLE,链接正常,但没有覆盖。
我怎样才能让一个带有覆盖层的图像在悬停时消失并变成一个链接但也是移动响应的?可能是一些 jquery?
【问题讨论】:
标签: jquery css image css-selectors hover