Reputation: 53
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;
}
Upvotes: 4
Views: 8565
Reputation: 273540
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>
Upvotes: 8
Reputation: 1047
Transition property need set to class if you want to use it for pseudo class
.mydiv {
background: red;
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
transition: all 0.5s ease;
}
.mydiv:hover {
background: blue;
clip-path: polygon(0% 0%, 100% 0%, 80% 100%, 0% 100%);
}
<div class="mydiv">
Hello world
</div>
Upvotes: 0