点击我的div

时间:2016-01-22 10:33:26

标签: html css href

我正在使用模块框,将用户重定向到外部网站。

我已设法创建布局并且内容显示正确,但是当我添加悬停效果时,div不再可点击,因此不会重定向到外部网站。

Here is my jsfiddle

这是我的代码:

<div class="module-box">
<div class="module-dummy"></div>
<div class="module-body module-pinterest">
    <a href="www.google.com">
        <div class="module-pinterest-title">Some text</div>
        <div class="module-pinterest-description">
Some other text</div>
    </a>
</div>

和我的CSS:

.module-box {
display: inline-block;
position: relative;
width: 100%;}

.module-dummy {
margin-top: 100%;}

.module-body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;}

.module-pinterest {
background-color: #7C56BE;}

.module-pinterest-title {
padding: 25px 25px 0px 25px;
color: #FFF;}

.module-pinterest-description {
padding: 25px 25px 0px 25px;
font-size: 22px;
line-height: 26px;
font-weight: bold;
color: #FFF;}

.module-pinterest:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.2);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;}

.module-pinterest:hover:after {
opacity:1;}

谢谢!

3 个答案:

答案 0 :(得分:2)

pointer-events:none;添加到您的.module-pinterest:hover:after css代码中,如下所示:

.module-pinterest:hover:after {
  opacity: 1;
  pointer-events:none;
}

Here is the JSFiddle demo

答案 1 :(得分:1)

如果您将所有.module-pinterest样式移动到锚点,那么它应该可以工作:

.module-pinterest a {
  display:block;
  width:100%;
  height:100%;
  background-color: #7C56BE;
}
.module-pinterest a:after {
    content:'\A';
    position:absolute;
    width:100%; height:100%;
    top:0; left:0;
    background:rgba(0,0,0,0.2);
    opacity:0;
    transition: all 0.5s;
    -webkit-transition: all 0.5s;
}
.module-pinterest a:hover:after {
    opacity:1;
}

Updated fiddle

答案 2 :(得分:0)

由于您使用positioningcolor上覆盖hover,因此请将您的主播转换为block并添加position:relativez-index值:

.module-body a {
  position: relative;
  z-index: 9;
  display:block;
}

这是小提琴: https://jsfiddle.net/kw5ybq9e/3/