I want to achieve a button that fills up like a battery. It will start with color red first then change to green on hover.
I know the fill up animation but the changing colors while filling up I cant achieve.
.outer {
margin: 50px;
}
.button {
border: 1px solid black;
border-radius: 3px;
width: 100px;
height: 30px;
display: block;
position: relative;
overflow: hidden;
background-color: green;
}
.button::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 20%;
height: 100%;
background-color: red;
transition: width 0.5s ease-out;
}
.button:hover::before {
width: 100%;
}
.text {
text-align: center;
font-size: 16px;
line-height: 30px;
color: black;
transition: color 0.6s ease-out;
display: block;
}
.button:hover .text {
color: white;
}
<div class="outer">
<button class="button">
<span class="text">Click me</span>
<span class="charging-animation"></span>
</button>
</div>
2
Answers
.button {background-color: red;} .button::before {width: 0%; background-color: green;}
Hope my code can help you. It just used css transition on both background color and width.