I want the color of a button to transition every time it's clicked. In the code snippet below, it transitions from green to blue.
The problem is that once the button has focus, the color doesn't change no matter how many times it's clicked. To reenable the effect I have to click somewhere else to make the button lose focus.
I thought the button:active
event would reset the process every time the button was clicked, but that doesn't seem to be the case.
button {
background: red;
color: black;
height: 50px;
width: 100px;
}
button:active {
background: green;
}
button:focus {
background: blue;
transition: all 3s ease;
}
<button>Click Me</button>