0

I am trying to currently trying to create an overlay for a card body in Bootstrap. But i am not sure how to proceed now because the overlay keeps blocking the button that is located inside the card and I need to be able to click on the button. Not sure what to do now, some help would be amazing.

enter image description here

Html is here:

    .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>
MaxiGui
  • 6,190
  • 4
  • 16
  • 33
Simasan
  • 17
  • 10

2 Answers2

2

Use z-index on the element you want to be on top. I usually start with a value of 9 and keep adding 9's until I get the desired effect.

i.e.:

.button {
  z-index: 9;
}
Martijn
  • 509
  • 6
  • 23
1

Image parent div need to be "position:relative" and overlay is "position: absolute". When you hover the image, Overlay display.

.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>
Ishita Ray
  • 672
  • 3
  • 8