【发布时间】:2015-01-30 09:44:15
【问题描述】:
我已经基于this tutorial 设置了一些图像悬停样式,它使用before 和after 伪元素创建悬停样式。
工作(并且看起来)很棒,但我需要能够在悬停内容中插入按钮/链接,但由于这是在伪元素上设置的,after 阻止了按钮/链接可点击。
如下所示,我设置了一个 jsfiddle 来演示我想要做什么 - 你会注意到,悬停时无法点击链接,我想知道是否有人可以建议一种无需完全改变其结构即可使该链接可点击的简单方法。
默认状态
悬停状态
.media {
display: inline-block;
position: relative;
vertical-align: top;
}
.media__image { display: block; }
.media__body {
background: rgba(41, 128, 185, 0.7);
bottom: 0;
color: white;
font-size: 1em;
left: 0;
opacity: 0;
overflow: hidden;
padding: 3.75em 3em;
position: absolute;
text-align: center;
top: 0;
right: 0;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.media__body:hover { opacity: 1; }
.media__body:after,
.media__body:before {
border: 1px solid rgba(255, 255, 255, 0.7);
bottom: 1em;
content: '';
left: 1em;
opacity: 0;
position: absolute;
right: 1em;
top: 1em;
-webkit-transform: scale(1.5);
-ms-transform: scale(1.5);
transform: scale(1.5);
-webkit-transition: 0.6s 0.2s;
transition: 0.6s 0.2s;
}
.media__body:before {
border-bottom: none;
border-top: none;
left: 2em;
right: 2em;
}
.media__body:after {
border-left: none;
border-right: none;
bottom: 2em;
top: 2em;
}
.media__body:hover:after,
.media__body:hover:before {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
.media__body h2 { margin-top: 0; }
.media__body p { margin-bottom: 1.5em; }
<div class="media">
<img class="media__image" src="http://lorempixel.com/400/300/animals" alt="" />
<div class="media__body">
<h2>Cool Title</h2>
<p>Lorem ipsum dolor sit amet, <a href="/mylink">consectetur adipisicing</a> elit. Nesciunt laboriosam voluptatem necessitatibus cum, tenetur repellat, eaque eos debitis! Quaerat.</p>
</div>
</div>
【问题讨论】:
标签: css