I wanted to add a effect where an icon showed up and disappeared smoothly when the button is hovered. The effect occurs with no issues when the button is hovered, but unlike other effects, it only works one way.
Note: I used Ionicons but the issue persists with several other icon libraries.
button {
font-size: 20px;
transition: 0.2s;
overflow: hidden;
}
.buttonicon {
position: relative;
font-size: 25px;
margin-bottom: -6px;
left: 100%;
width: 0;
}
button:hover .buttonicon {
transition: 1s;
left: 0;
width: 20px;
}
<script src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
<button>
Button Text
<ion-icon class="buttonicon" name="chevron-forward-outline"></ion-icon>
</button>