CSS animation with different effects on :hover and :active?


EDIT Demo is here : http://3.cnxical.appspot.com

The text-shadow property changes on hover, and with animation-fill-mode set forwards the state persists.

The animation for the :active state does not work, and nothing happens when the title is clicked.

The expected behaviour is the title should disappear because the text-shadow property was set to (and both of these were tried) none or 0 0 1px transparent. Setting text-shadow for :active was also tried without an animation and it did not work.

How can the correct behaviour be achieved?

The code is :

            #title {
                text-shadow:0 0 10px lime;
                font-family:"Courier New",Courier,monospace;
                -webkit-animation: push_title_focus 0.3s;
            #title:active {
                -webkit-animation: vanish_title 0.3s;   
            #title:hover {
                -webkit-animation: pull_title_focus 0.3s;
                -webkit-animation-fill-mode: forwards;
            @-webkit-keyframes pull_title_focus {
                from { text-shadow: 0 0 10px lime; }
                to { text-shadow: 0 0 1px lime; }
            @-webkit-keyframes push_title_focus {
                from { text-shadow: 0 0 1px lime; }
                to { text-shadow: 0 0 10px lime; }
            @-webkit-keyframes vanish_title {
                from { text-shadow: 0 0 1px lime; }
                to { text-shadow: none !important; }
Problem courtesy of: Cris


When you press the mouse button down to activate the link, the mouse is still pointing to it, so it is still being hovered.

#title:hover and #title:active are equally specific, and the hover rule is defined last.

Any rules with properties that are specified in both rule-sets, will be overridden by the :hover rule (including -webkit-animation).

Reorder your rulesets so the :hover rule appears before the :active rule.

Solution courtesy of: Quentin


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.