Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover transition on clip path change

With this code ,the hover effect is working ,the bottom right corner disappears but there is no transition,it's something wrong?

.mydiv:hover{
      background-color: blue;
      clip-path: polygon(0% 0%, 100% 0%, 80% 100%, 0% 100%);
      transition: 0.5s ease;
 }
like image 785
afs125874 Avatar asked Sep 20 '25 06:09

afs125874


1 Answers

You need to add an initial clip-path definition to have a transition between two states:

.box {
  background-color: blue;
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
  transition: 0.5s ease;
  height:150px;
}

.box:hover {
  clip-path: polygon(0% 0%, 100% 0%, 80% 100%, 0% 100%);
}
<div class="box">

</div>

You can also do the same with background and you will have better support:

.box {
  background: 
    linear-gradient(blue,blue) left,
    linear-gradient(to bottom right,blue 49.5%,transparent 50%) right;
  background-size:100% 100%,0% 100%;
  background-repeat:no-repeat;
  transition: 0.5s ease;
  height:150px;
}

.box:hover {
  background-size:80.1% 100%,20% 100%;
}
<div class="box">

</div>
like image 109
Temani Afif Avatar answered Sep 22 '25 04:09

Temani Afif