Issue
I have the following code for a span inside a div:
<div class="mission-button"><span class="mission">view our mission</span></div>
And the following css:
.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: var(--main-dark);
animation: borderOnLoad 2s forwards;
}
@keyframes changeColor {
0% {
letter-spacing: 0px;
color: white;
}
100% {
letter-spacing: 2px;
color: var(--main-dark);
}
}
@keyframes borderOnLoad {
0% {
width: 100%;
border-left-width: 3px;
border-right-width: 3px;
height: 100%;
top: 0;
color: white;
background-color: var(--main-dark);
}
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: var(--main-dark);
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;
}
.mission-button:hover::before {
width: 32%;
border-left-width: 200px;
border-right-width: 200px;
height: 1px;
top: 30px;
}
The changeColor and borderOnLoad animations are working as expected but when I hover the div, I'd like the span to change it's letter-spacing via:
.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;
}
but it's doing anything. I'm thinking it's because there's already an animation for the mission-button and that one is taking priority over the rest, but I don't know
Solution
This is because you've set the animation-fill-mode
to forwards
, which maintains the styles of the last keyframe, including line-spacing:2px
. It might make more sense to move 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 can't change the original spacing, to overwrite it you can either use !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>
Or wrap the text in another container and specify the style on that container:
.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>
Answered By - SyndRain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.