锚标签不可点击的文本重叠问题



在下面的fiddle中,我在这个结构中有一个带有href和背景图像的锚标记,文本正在停止href以点击。有没有想法如何解决这个问题,使用相同的HTML结构?

<div class="banner-container">
<div class="banner-box">
<div class="banner-div">
<div class="bannerheading">
<p><span>The correct link should be&nbsp;</span></p>
</div>
</div>
<a href="https://www.google.com/">
<div class="banner-img" style="background-image:url('https://ssl.gstatic.com/gb/images/i1_1967ca6a.png');">
</div>
</a>
</div>

请检查框内的红色边框是否无法点击https://jsfiddle.net/uqbhcdn6/1/.

任何想法都将不胜感激:(

pointer-events:none;属性添加到.banner-div类中。

一种可能性是给.bannerheading提供样式pointer-events: none;,尽管这将使其无法选择.bannerheading:中的文本

.banner-container {
min-height: 300px;
position: relative;
margin-bottom: 20px;
}
.banner-container .banner-box {
border-radius: 12px;
min-height: 350px;
background-color: #1C2841;
overflow: hidden;
}
.banner-container .banner-box .banner-div {
top: 50%;
height: auto;
-ms-transform: translateY(-50%);
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
padding: 20px;
z-index: 3;
border-radius: 12px;
border:1px solid red;
}
.banner-div {
position: absolute;
width: 100%;
height: 100%;
z-index: 999;
top: 34%;
padding: 10px;
pointer-events: none;
}
.banner-container .banner-box .banner-div .bannerheading {
color: #fff;
}
banner-container .banner-box .banner-img {
min-height: 350px;
border-radius: 12px;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
-webkit-transform: scale(1);
-ms-transform: scale(1);
-moz-transform: scale(1);
transform: scale(1);
}
.banner-img {
height: 100%;
width: 100%;
min-height: 300px;
background-size: cover;
background-position: center;
}
<div class="banner-container">
<div class="banner-box">
<div class="banner-div">
<div class="bannerheading">
<p><span>The correct link should be&nbsp;</span></p>
</div>
</div>
<a href="https://www.google.com/">
<div class="banner-img" style="background-image:url('https://ssl.gstatic.com/gb/images/i1_1967ca6a.png');">
</div>
</a>
</div>
</div>

您可以通过两种方法解决

1.您可以为要应用的z索引添加z-indexposition:relative

2.可以添加pointer-events:none

相关内容

  • 没有找到相关文章

最新更新