- by the
transform property,now we can can be revisited with alternative ways to size, position, and change elements. - It's take two different settings,
two-dimensionalandthree-dimensional.
- It's including the
transform propertyfollowed by thevalue. The value specifies the transform type followed by a specific amount inside parentheses.
Example:
div {
transform: scale(1.5);
}
- 2D Rotate
rotate valueprovides the ability to rotate an element from0 to 360degrees.
Example:
.box-1 {
transform: rotate(20deg);
}
.box-2 {
transform: rotate(-55deg);
}
- 2D Scale
scale valueallows you to change the appeared size of an element.
Example:
.box-1 {
transform: scale(.75);
}
.box-2 {
transform: scale(1.25);`
}
It can also write for each axis as :
.box-1 {transform: scaleX(.5);}//.box-2 {transform: scaleY(1.15);}//.box-3 {transform: scale(.5, 1.15);}
- 2D Translate
translate valueworks a bit like that of relative positioning, pushing and pulling an element in different directions without interrupting the normal flow of the document,by using thetranslateX valueand thetranslateY value.
Example:
box-1 {
transform: translateX(-10px);
}
.box-2 {
transform: translateY(25%);
}
.box-3 {
transform: translate(-10px, 25%);
}
- 2D Skew
skew, is used to distort elements on thehorizontal axis, vertical axis, or both.
Example:
.box-1 {
transform: skewX(5deg);
}
.box-2 {
transform: skewY(-20deg);
}
.box-3 {
transform: skew(5deg, -20deg);
}
- Combining Transforms
- it's multipling transforms to be used at once, rotating and scaling the size of an element at the same time for example.
Example:
.box-1 {
transform: rotate(25deg) scale(.75);
}
.box-2 {
transform: skew(10deg, 20deg) translateX(20px);
}
- Transform Origin
transform-origin propertymay be used to change this default origin positionfor the default transform origin that is the centeralized of an element, both 50% horizontally and 50% vertically.
Example:
box-1 {
transform: rotate(15deg);
transform-origin: 0 0;
}
.box-2 {
transform: scale(.5);
transform-origin: 100% 100%;
}
.box-3 {
transform: skewX(20deg);
transform-origin: top left;
}
.box-4 {
transform: scale(.75) translate(-10px, -10px);
transform-origin: 20px 50px;
}
- Perspective
perspectiveit's like a vanishing point, similar to that which can be seen in three-dimensional drawings.
Example:
.box {
transform: perspective(200px) rotateX(45deg);
}
- It's an element must have a change in state, and different styles must be identified for each state.,it's determining styles for different states by using the
:hover, :focus, :active, and :target pseudo-classes.
Example:
.box {
background: #2db34a;
transition-property: background;
transition-duration: 1s;
transition-timing-function: linear;
}
.box:hover {
background: #ff7b29;
}
- Transitional Property
transition-propertyit's determines exactly what properties will be altered in conjunction with the other transitional properties.
Example:
transition-property: background, border-radius;
the more popular transitional properties include the following:
<background-color,background-position,border-color,border-width,border-spacing,bottom,clip,color,crop,font-size,font-weight,height,left,letter-spacing,line-height,margin,max-height,max-width,min-height,min-width,opacity,outline-coloro,utline-offset,outline-width,padding,right,text-indent,text-shadow,top,vertical-align,visibility,width,word-spacing,z-index.>
- Transition Duration
- The duration in which a transition takes place is set using the
transition-duration property.
- The duration in which a transition takes place is set using the
Example:
transition-duration: .2s, 1s;
- Transition Timing
transition-timing-function propertyis used to set the speed in which a transition will move.
Example:
transition-timing-function: linear, ease-in;
A few of the more popular keyword values for the transition-timing-function property:
-
linear, ease-in, ease-out, and ease-in-out. -
Transition Delay
transition-delay propertyto determines how long a transition should be stalled before executing.
Example:
.box {
background: #2db34a;
border-radius: 6px
transition-property: background, border-radius;
transition-duration: .2s, 1s;
transition-timing-function: linear, ease-in;
transition-delay: 0s, 1s;
}
.box:hover {
background: #ff7b29;
border-radius: 50%;
}
- Shorthand Transitions
shorthand propertyby usingtransition, is capable of supporting allthe previous properties and values.
Example:
.box {
background: #2db34a;
border-radius: 6px;
transition: background .2s linear, border-radius 1s ease-in 1s;
}
.box:hover {
color: #ff7b29;
border-radius: 50%;
}
Animations Keyframes- The
@keyframes ruleincludes the animation name, any animation breakpoints, and the properties intended to be animated.
Example:
@keyframes slide {
0% {
left: 0;
top: 0;
}
50% {
left: 244px;
top: 100px;
}
100% {
left: 488px;
top: 0;
}
}
- Animation Name
animation-name propertyis used with the animation name, identified from the@keyframes rule, as the propertyvalue.
it's applied to the element in which the animation is to be applied to.
Example:
.stage:hover .ball {
animation-name: slide;
}
- Animation Duration, Timing Function, & Delay
- to start, animations need a duration declared using the
animation-duration property.
- to start, animations need a duration declared using the
Example:
.stage:hover .ball {
animation-name: slide;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: .5s;
}
- Animation Iteration
animation-iteration-count propertyused to have an animation repeat itself numerous times.
Using an
integerwill repeat the animation as many times as specified, while theinfinitekeyword will repeat the animation indefinitely in a never ending fashion.
Example:
.stage:hover .ball {
animation-name: slide;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: .5s;
animation-iteration-count: infinite;
}
- Animation Direction
animation-direction propertyused when you want to set the number of times to an animation repeats.
Values for the
animation-direction propertyincludenormal, reverse, alternate, and alternate-reverse.
Example:
.stage:hover .ball {
animation-name: slide;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: .5s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
- Animation Play State
animation-play-state propertyallows an animation to beplayed or pausedusing therunning and pausedkeyword values respectively.
Example:
.stage:active .ball {
animation-play-state: paused;
}
- Animation Fill Mode
animation-fill-mode propertyidentifies how an element should be styled either before, after, or before and after an animation is run.
The
animation-fill-mode propertyaccepts four keyword values, includingnone, forwards, backwards, and both.
Example:
.stage:hover .ball {
animation-name: slide;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: .5s;
animation-fill-mode: forwards;
}
- Shorthand Animations
- It can be written out in a shorthand format with one
animation property.
- It can be written out in a shorthand format with one
Example:
.stage:hover .ball {
animation: slide 2s ease-in-out .5s infinite alternate;
}
References:
@Shay Howe /Transforms, Transitions, and Animations