How to stop the overlay to cover the content and make it cover only the background?

Issue

I am using ::before as an overlay, but I face a problem where the overlay cover all the card including the content (texts), but I just want to cover the background of the card. I can’t select any text because of this problem.

/* left-to-right effect box */
.ltr-effect {
    position: relative;
}
.ltr-effect::before {
    content: "";
    display: block;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 0%;
    height: 100%;
    background-color:rgba(215, 227, 250, 0.53);
    transition: width 0.5s;
}
.ltr-effect:hover::before {
    width: 100%;
}

/* card */
.service-content-box {
    text-align: center;
    border: 2px solid rgb(208, 228, 228);
    background-color: #22beff;
    border-radius: 10px;
    padding: 30px;
    font-size: 1.3em;
    width: calc(90%/3);
    margin-right: 5%;
    position: relative;
}
/* content of services */
.service-content-box .service-title {
    text-transform: capitalize;
    margin-bottom: 10px;
    font-size: 2em;
}
.service-content-box .service-desribtion {
    line-height: 30px;
}
.service-content-box a {
    margin: 7px 0px;
    text-decoration: none;
    text-transform: capitalize;
}
 <section class="services">
  <div class="services-content">
    <div class="service-content-box ltr-effect">
      <i class="fa fa-solid fa-book-open"></i>
      <h4 class="service-title mg-b-10">fast reading</h4>
      <p class="service-desribtion">
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. A fugiat, ea et iure similique nesciunt Et accusantium                              magni
      </p>
      <a href="#" class="read-more">learn more</a>
    </div>
    <div class="clear"></div>
  </div><!-- /.services-content -->
    </section><!-- /.services -->

Solution

You coud set a position: relative; z-index: 1; to elements in the card that you don’t wanna cover with the overlay.

You need z-index to make them came up front, and as you may already know, z-index works only with non static positions. That’s why I’m using that relative position.

/* left-to-right effect box */
.ltr-effect {
  position: relative;
}
.ltr-effect::before {
  content: "";
  display: block;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 0%;
  height: 100%;
  background-color: rgba(215, 227, 250, 0.53);
  transition: width 0.5s;
}
.ltr-effect:hover::before {
  width: 100%;
}

/* card */
.service-content-box {
  text-align: center;
  border: 2px solid rgb(208, 228, 228);
  background-color: #22beff;
  border-radius: 10px;
  padding: 30px;
  font-size: 1.3em;
  width: calc(90% / 3);
  margin-right: 5%;
  position: relative;
}
/* content of services */
.service-content-box .service-title {
  text-transform: capitalize;
  margin-bottom: 10px;
  font-size: 2em;
  position:relative;
  z-index:1;
}
.service-content-box .service-desribtion {
  line-height: 30px;
  position:relative;
  z-index:1;
}
.service-content-box a {
  margin: 7px 0px;
  text-decoration: none;
  text-transform: capitalize;
  position:relative;
  z-index:1;
}
<section class="services">
  <div class="services-content">
    <div class="service-content-box ltr-effect">
      <i class="fa fa-solid fa-book-open"></i>
      <h4 class="service-title mg-b-10">fast reading</h4>
      <p class="service-desribtion">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. A fugiat, ea et iure similique nesciunt Et accusantium magni
      </p>
      <a href="#" class="read-more">learn more</a>
    </div>
    <div class="clear"></div>
  </div>
</section>

Answered By – yousoumar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published