Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

summarize two CSS-keyframes

summarize two CSS-keyframes

Problem

I've two css-keyframes. They only differentiate by one statement:

@keyframes expand-t{
0%{
    width: 50%;
    height: 50%;
    z-index: 100;
}
50%{
    height: 50%;
    z-index: 100;

    top: 0;
    left: 0;
    width: 100%;
}
100%{
    z-index: 100;
    top: 0;
    left: 0;
    width: 100%;

    height: 100%;
}

}
@keyframes expand-b{

0%{
    width: 50%;
    height: 50%;
    z-index: 100;
}
50%{
    height: 50%;
    z-index: 100;

    top: 50%;
    left: 0;
    width: 100%;
}
100%{
    z-index: 100;
    top: 0;
    left: 0;
    width: 100%;

    height: 100%;
}

}

At 50% in the expand-t I change the top to 0 while I change the top in expand-b to 50%. The rest of the code is similar.
How can I summarize this to avoid redundand code?

PS: I won't use LESS or SCSS or what ever. When possible a CSS-only way!

Problem courtesy of: user2413035

Solution

You can't summarize the keyframes without some kind of preprocessor.

From the Mozilla Developer Network:

If multiple keyframe sets exist for a given name, the last one encountered is used. @keyframes rules don't cascade, so animations never drive keyframes from more than one rule set.

Solution courtesy of: cizmic

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

summarize two CSS-keyframes

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×