william44isme
william44isme

Reputation: 877

CSS animations not working

I have a simple CSS animation to fade in text:

#title{
    animation: text 2s;
    -webkit-animation: text 2s;
    -moz-animation: text 2s;
    -o-animation: text 2s;
    font-family: 'Lato300', sans-serif;
    height: 115px;
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    margin-bottom: auto;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

@keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-moz-keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-webkit-keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-o-keyframes text{
        0% {display: none;}
    100% {display: inline;}
}

The HTML:

<div id="title"><h1>Text goes here</h1></div>

For some reason, the animation doesn't play. Does anyone know why? (I kept all the code incase something else is causing the problem)

Upvotes: 1

Views: 3086

Answers (3)

Friendly Code
Friendly Code

Reputation: 1655

For anyone in the future experiencing a similar issue I solved this by adding

display:block

to the span I was trying to animate

Upvotes: 0

Nik Drosakis
Nik Drosakis

Reputation: 2348

shake
 @-webkit-keyframes text {
    0%, 100% {-webkit-transform: translateX(0);}
    10%, 30%, 50%, 70%, 90% {-webkit-transform: translateX(-10px);}
    20%, 40%, 60%, 80% {-webkit-transform: translateX(10px);}
} 

or rotate
@-webkit-keyframes text {
    0% {-webkit-transform: scale(1);}   
    10%, 20% {-webkit-transform: scale(0.9) rotate(-3deg);}
    30%, 50%, 70%, 90% {-webkit-transform: scale(1.1) rotate(3deg);}
    40%, 60%, 80% {-webkit-transform: scale(1.1) rotate(-3deg);}
    100% {-webkit-transform: scale(1) rotate(0);}
}

Upvotes: 0

dfsq
dfsq

Reputation: 193301

You will not be able to animate display property. However you can transition an opacity

@-webkit-keyframes text {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

http://jsfiddle.net/5FCZA/

Upvotes: 1

Related Questions