One reason for this behavior is the animation-fill-mode
being set to forwards
, which retains the styles of the last keyframe, such as line-spacing:2px
. A better approach might be to transfer the original line-spacing of 2px from the last keyframe to .mission
:
@keyframes changeColor {
0% {
letter-spacing: 0px;
color: white;
}
100% {
color: black;
}
}
.mission {
letter-spacing: 2px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
cursor: pointer;
animation: changeColor 2s forwards;
}
.mission-button:hover .mission{
letter-spacing: 5px;
}
.mission-button::before {
content:'';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 1s;
border-left-width: 2px;
border-right-width: 2px;
border-left-style: solid;
border-right-style: solid;
background-color: transparent;
border-color: black;
animation: borderOnLoad 2s forwards;
}
@keyframes changeColor {
0% {
letter-spacing: 0px;
color: white;
}
100% {
color: black;
}
}
@keyframes borderOnLoad {
0% {
width: 100%;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
background-color: black;
}
50% {
width: 200%;
left: -150px;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
}
100% {
width: 65%;
left: -150px;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
color: black;
background-color: transparent;
}
}
.mission-button {
padding: 20px;
/* background-color: #083958;*/
cursor: pointer;
width: 50%;
position: relative;
margin-top: 20px;
font-size: 20px;
text-align: center;
}
.mission {
letter-spacing: 2px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
cursor: pointer;
animation: changeColor 2s forwards;
}
.mission-button:hover .mission{
letter-spacing: 5px;
}
.mission-button:hover::before {
width: 32%;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
}
<div class="mission-button"><span class="mission">view our mission</span></div>
If you are unable to modify the original spacing, you can override it by using !important
:
.mission-button:hover .mission{
letter-spacing: 5px !important;
}
.mission-button::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 1s;
border-left-width: 2px;
border-right-width: 2px;
border-left-style: solid;
border-right-style: solid;
background-color: transparent;
border-color: black;
animation: borderOnLoad 2s forwards;
}
@keyframes changeColor {
0% {
letter-spacing: 0px;
color: white;
}
100% {
letter-spacing: 2px;
color: black;
}
}
@keyframes borderOnLoad {
0% {
width: 100%;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
background-color: black;
}
50% {
width: 200%;
left: -150px;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
}
100% {
width: 65%;
left: -150px;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
color: black;
background-color: transparent;
}
}
.mission-button {
padding: 20px;
/* background-color: #083958;*/
cursor: pointer;
width: 50%;
position: relative;
margin-top: 20px;
font-size: 20px;
text-align: center;
}
.mission {
letter-spacing: 0px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
cursor: pointer;
animation: changeColor 2s forwards;
}
.mission-button:hover .mission {
letter-spacing: 5px !important;
}
.mission-button:hover::before {
width: 32%;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
}
<div class="mission-button"><span class="mission">view our mission</span></div>
Alternatively, you can wrap the text in another container and define the style there:
.mission-button:hover .text-spacing{
letter-spacing: 5px;
}
<div class="mission-button">
<span class="mission">
<div class="text-spacing">view our mission</div>
</span>
</div>
.mission-button::before {
content:'';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 1s;
border-left-width: 2px;
border-right-width: 2px;
border-left-style: solid;
border-right-style: solid;
background-color: transparent;
border-color: black;
animation: borderOnLoad 2s forwards;
}
@keyframes changeColor {
0% {
letter-spacing: 0px;
color: white;
}
100% {
letter-spacing: 2px;
color: black;
}
}
@keyframes borderOnLoad {
0% {
width: 100%;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
background-color: black;
}
50% {
width: 200%;
left: -150px;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
}
100% {
width: 65%;
left: -150px;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
color: black;
background-color: transparent;
}
}
.mission-button {
padding: 20px;
/* background-color: #083958;*/
cursor: pointer;
width: 50%;
position: relative;
margin-top: 20px;
font-size: 20px;
text-align: center;
}
.mission {
letter-spacing: 0px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
cursor: pointer;
animation: changeColor 2s forwards;
}
.mission-button:hover .text-spacing{
letter-spacing: 5px;
}
.mission-button:hover::before {
width: 32%;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
}
<div class="mission-button">
<span class="mission">
<div class="text-spacing">view our mission</div>
</span>
</div>