6

I want to make two different styles for two blinking class using html and css. My sample code is as follows:

.blinking{
    animation:blinkingText 0.8s infinite;
}
.blinking2{
    animation:blinkingText 0.8s infinite;
}
@keyframes blinkingText{
    0%{ color: #000;    }
    49%{    color: red; }
    50%{    color: red; }
    99%{    color: red; }
    100%{   color: #000;    }
}
<span class="blinking">Am I blinking?</span><br/>
<span class="blinking2">Am I blinking?</span>

I want to make blinking2 class yellow colored. is there any way to achiive this?

2

2 Answers 2

2

You can use another keyframe for the other blinkingText(yellow).

Try this:

.blinking{
    animation:blinkingText 0.8s infinite;
}
.blinking2{
    animation:blinkingText2 0.8s infinite;
}
@keyframes blinkingText{
    0%{ color: #000;    }
    49%{    color: red; }
    50%{    color: red; }
    99%{    color: red; }
    100%{   color: #000;    }
}
@keyframes blinkingText2{
    0%{ color: #000;    }
    49%{    color: yellow; }
    50%{    color: yellow; }
    99%{    color: yellow; }
    100%{   color: #000;    }
}
<span class="blinking">Am I blinking?</span><br/>
<span class="blinking2">Am I blinking?</span>

Sign up to request clarification or add additional context in comments.

1 Comment

@user10903858 it is, look carefully or just change the color.
1

Use CSS variables and you will only need one keyframe:

.blinking{
    animation:blinkingText 1s infinite;
}
.yellow{
    --c:yellow;
}
@keyframes blinkingText{
    0%{ color: #000;    }
    49%{    color: var(--c,lightblue); }
    50%{    color: var(--c,lightblue); }
    99%{    color: var(--c,lightblue); }
    100%{   color: #000;    }
}
<span class="blinking">Am I blinking?</span><br>
<span class="blinking yellow">Am I blinking?</span><br>
<span class="blinking" style="--c:lightgreen">Am I blinking?</span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.