1

.parent {
    width: 100%;
    margin: 20px;
    height: 350px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
}

.child {
    height: 100%;
    width: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -o-transition: all 1s;
    transition: all 1s;
}

.products-link {
    display: none;
    font-size: 18px;
    font-weight: bold;
    color: #ffffff !important;
    font-family: sans-serif;
    text-align: center;
    margin: auto;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    height: 50px;
    cursor: pointer;
}

.parent:hover .child, .parent:focus .child {
    -ms-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -webkit-transform: scale(1.2);
    -o-transform: scale(1.2);
    transform: scale(1.2);
}

.parent:hover .child:before, .parent:focus .child:before {
    display: block;
    background: linear-gradient(to bottom,rgba(126,206,213,0.40) 25%,rgba(126,206,213,0.90) 100%);
}

.parent:hover span, .parent:focus span {
    display: block;
}

.child:before {
    content: "";
    display: none;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-transition: all 2s;
    -moz-transition: all 2s;
    -o-transition: all 2s;
    transition: all 2s;
}

.bg-one {
    background-image: url(https://cdn.mos.cms.futurecdn.net/vEcELHdn998wRTcCzqV5m9.jpg);
    background-repeat: no-repeat;
    background-position: center;
}
<div class="parent">
    <a href="#">
       <div class="child bg-one">
          <span class="products-link">Title 1</span>
       </div>
    </a>
</div>

What I'm trying to achieve is to show a transition effect for .parent:hover .child:before, .parent:focus .child:before, which will make the background gradient show up and have a transition time.

I've tried using the same method for my zoom-in effect for .parent:hover .child, .parent:focus .child, and it works.

I also want the same transition to work for the text but it's the same issue with the background-gradient.

So I'm wondering what's causing the transition effect to not work on the pseudo element(:before)?

Lance
  • 215
  • 1
  • 6
  • 21

0 Answers0