我目前正在尝试为Bootstrap中的卡体创建一个覆盖。但我不确定现在如何继续,因为覆盖层不断阻止位于卡内的按钮,而我需要能够单击该按钮。不知道现在该怎么做,如果能帮上忙就太好了。

Html在这里:
.rafting {
background-image: url(./img/rafting.jpg);
background-size: cover;
color: white;
}
.rafting:before {
content: "";
position: absolute;
left: 0; right: 0;
top: 0; bottom: 0;
background: rgba(0,0,0,.5);
}<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<section class="offres">
<h2 class="text-center">NOS OFFRES</h2>
<div class="container">
<div class="row text-center">
<div class="column">
<img class="mb-5" src="./img/picto-logo/picot1.png" alt="Snow" style="width:65%">
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
<div class="column">
<img class="mb-5" src="./img/picto-logo/picot2.png" alt="Forest" style="width:65%">
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
<div class="column">
<img class="mb-5" src="./img/picto-logo/picot3.png" alt="Mountains" style="width:65%">
<a href="#" class="btn btn-primary">Hello</a>
</div>
</div>
</div>
</section>
发布于 2020-10-13 22:09:37
在要放在顶部的元素上使用z-index。我通常从值9开始,然后不断添加9,直到得到想要的效果。
即:
.button {
z-index: 9;
}发布于 2020-10-13 22:19:55
图像父div需要是"position:relative“,overlay是"position: absolute”。将鼠标悬停在图像上时,会覆盖显示。
.column {
width: 300px;
color: white;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.column:before {
content: "";
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(0, 0, 0, .5);
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
transition: all 300ms ease;
}
.column img {
width: 100%;
}
.btn-primary {
position: absolute;
z-index: 2;
}
.column:hover:before {
opacity: 1;
transition: all 300ms ease;
}<section class="offres">
<h2 class="text-center">NOS OFFRES</h2>
<div class="container">
<div class="row text-center">
<div class="column">
<img class="mb-5" src="https://images.pexels.com/photos/844297/pexels-photo-844297.jpeg" alt="Snow">
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
<div class="column">
<img class="mb-5" src="https://images.pexels.com/photos/844297/pexels-photo-844297.jpeg" alt="Forest">
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
<div class="column">
<img class="mb-5" src="https://images.pexels.com/photos/844297/pexels-photo-844297.jpeg" alt="Mountains">
<a href="#" class="btn btn-primary">Hello</a>
</div>
</div>
</div>
</section>
https://stackoverflow.com/questions/64336725
复制相似问题