Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css scale div from 0.1 to 1?

Tags:

css

I know how to scale from 1 to 2:

transition: all 1s ease-in-out;
transform: rotate(360deg) scale(2);

But I need from 0.1 to 1. Is there any way to do it?

like image 259
JohnyFree Avatar asked May 06 '14 15:05

JohnyFree


People also ask

How do I scale down CSS?

scale() The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.

How do I scale elements in CSS?

The default value for scale() is: scale(1) . To make an element twice as large, write 2 as the value: scale(2) . One scale() value evenly scales an element both vertically and horizontally. scale() accepts a second number value inside the parenthesis.

Can I use scale CSS?

And, yes, we can use scale in CSS transitions and animations.


1 Answers

You have two options, using animation or transition, both will work as anticipated as long as you specify the starting values. animation is typically the preferred option when you want more control over the intermediate keyframes, or the immediate application of an animation.

HTML

<div></div>

Using animation

div {
    background:red;
    height:100px;
    width:100px;
    -webkit-transform: scale(0.1);
    transform: scale(0.1);
    -webkit-animation: transformer 4s ease-in 0s 1;
    animation: transformer 4s ease-in 0s 1;
}
@-webkit-keyframes transformer {
    from {
        -webkit-transform: rotate(0deg) scale(0.1);
    }
    to {
        -webkit-transform: rotate(360deg) scale(2);
    }
}
@keyframes transformer {
    from {
        transform: rotate(0deg) scale(0.1);
    }
    to {
        transform: rotate(360deg) scale(2);
    }
}

Using transition

div {
    width:100px;
    height:100px;
    background:red;
    transition: all 1s ease-in;
    -webkit-transform: rotate(0deg) scale(0.1);
    transform: rotate(0deg) scale(0.1);
}
div:hover {
    -webkit-transform: rotate(360deg) scale(1);
    transform: rotate(360deg) scale(1);
}
like image 126
SW4 Avatar answered Sep 18 '22 14:09

SW4