Home > Software design >  How to stop the overlay to cover the content and make it cover only the background?
How to stop the overlay to cover the content and make it cover only the background?

Time:06-10

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 >
  <div >
    <div >
      <i ></i>
      <h4 >fast reading</h4>
      <p >
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. A fugiat, ea et iure similique nesciunt Et accusantium                              magni
      </p>
      <a href="#" >learn more</a>
    </div>
    <div ></div>
  </div><!-- /.services-content -->
    </section><!-- /.services -->

CodePudding user response:

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-indexworks only with relative, fixed, and sticky position. 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 >
  <div >
    <div >
      <i ></i>
      <h4 >fast reading</h4>
      <p >
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. A fugiat, ea et iure similique nesciunt Et accusantium magni
      </p>
      <a href="#" >learn more</a>
    </div>
    <div ></div>
  </div>
</section>

  • Related