Wordcamp Lancaster, February 27, 2015
by Beth Soderberg | @bethsoderberg
"to change in form, appearance, or structure; metamorphose"
“The CSS transform property lets you modify the coordinate space of the CSS visual formatting model. Using it, elements can be translated, rotated, scaled, and skewed according to the values set.”
transform: none;
transform: <transform-function>;
transform: <transform-function> <transform-function> <transform-function>;
Rotates an element clockwise from its current position. Counter clockwise rotations can be achieved by using negative values.
transform: rotate(angle);
* angles are expressed as (5deg) or (-5deg), for example.
.box {
width: 3em;
height: 3em;
background: #ca0164;
}
.box .fa {
font-size: 2em;
line-height: 1.45em;
text-align: center;
}
.box {
transform: rotate(25deg);
}
.box {
transform: rotate(-25deg);
}
Scales an element relative to its original size. The values specified within scale transforms are unitless and should be thought of as a multiplier.
transform: scale(valueX, valueY);
* if only valueX is specified, valueY is assumed to be equal to valueX
transform: scaleX(valueX);
transform: scaleY(valueY);
.box {
transform: scale(0.5);
}
.box {
transform: scale(1, 2);
}
Skews an element along the X and/or Y axis by an angle value.
transform: skew(angleX, angleY);
* do not use, no longer in specification
transform: skewX(angleX);
transform: skewY(angleY);
.box {
transform: skewX(25deg);
}
.box {
transform: skewX(25deg) skewY(25deg);
}
Moves an element vertically and/or horizontally relative to its current position. Positive values will move the element right on the X axis or down on the Y axis. Conversely, negative values will move the element left on the X axis or up on the Y axis. Any regular length value can be used (px, em, etc.)
transform: translate(valueX, valueY);
transform: translateX(valueX);
transform: translateY(valueY);
.box-wrap {
width: 6em;
height: 6em;
border: 5px solid #F5B54B;
}
.box {
transform: translate(3em, 3em);
}
Think of translate as a more efficient way to move placement in a transition or animation.
A CSS property that defines the point from which a CSS transform is applied to an element. By default, transform-origin is set to the center of an element (50% 50%).
transform-origin: x-offset y-offset;
x-offset: a length or percentage from the left edge of the element's box.
y-offset: a length or percentage from the top edge of the element's box.
.box {
transform: rotate(-25deg);
transform-origin: 100% 0%;
}
.box {
transform: rotate(-25deg);
transform-origin: right bottom;
}
NOTE: 3d transforms are coming and can be used in a lot of browsers now, but they are only partially supported in IE10 and 11.
"movement, passage, or change from one position, state, stage, subject, concept, etc., to another; change"
“The transition property is a shorthand property used to represent up to four transition-related longhand properties [that] allow elements to change values over a specified duration, animating the property changes, rather than having them occur immediately.”
transition: <property> <duration> <timing-function> <delay>;
transition-property: <property>;
transition-duration: <duration>;
transition-timing-function: <timing-function>;
transition-delay: <delay>;
Specifies which property or properties will be impacted by the transition.
transition-property: value;
.box {
transition-property: color, background-color, width;
color: #ffffff;
background-color: #ca0164;
width: 3em;
}
.box:hover {
color: #384042;
background-color: #F5B54B;
width: 3.6em;
}
Specifies the amount of time the transition will take.
transition-duration: value;
.box {
transition-property: color, background-color, width;
transition-duration: 2s;
color: #ffffff;
background-color: #ca0164;
width: 3em;
}
.box:hover {
color: #384042;
background-color: #F5B54B;
width: 3.6em;
}
Specifies the pace at which the transition will run.
transition-timing-function: value;
For an in-depth explanation of the transition timing property, check out this article: http://www.the-art-of-web.com/css/timing-function/
.box {
transition-property: color, background-color, width;
transition-duration: 2s;
transition-timing-function: ease-in-out;
color: #ffffff;
background-color: #ca0164;
width: 3em;
}
.box:hover {
color: #384042;
background-color: #F5B54B;
width: 3.6em;
}
Specifies when the transition will start relative to the instant the property value changes.
transition-delay: value;
.box {
transition-property: color, background-color, width;
transition-duration: 2s;
transition-timing-function: ease-in-out;
transition-delay: 3s;
color: #ffffff;
background-color: #ca0164;
width: 3em;
}
.box:hover {
color: #384042;
background-color: #F5B54B;
width: 3.6em;
}
"the state or condition of being animated"
"containing representations of animals or mechanical objects that appear to move as real ones do"
“A way for authors to animate the values of CSS properties over time, using keyframes. The behavior of these keyframe animations can be controlled by specifying their duration, number of repeats, and repeating behavior.”
Keyframes establish the behavior of an animation over time.
Specifies the length of time one cycle of the animation will take.
animation-duration: value;
Specifies the animation/s that should be applied to the CSS element.
animation-name: custom-value;
Specifies the number of times the animation cycle should run.
animation-iteration-count: value;
.element {
animation-duration: value;
animation-name: custom-value;
}
*Optional animation properties would be included in the same code block as animation-duration and animation-name.
@keyframes [animation name] {
[keyframe location] {
[CSS properties];
}
[keyframe location] {
[CSS properties];
}
}
[animation name]: the animation-name string from your CSS
[keyframe location]: waypoint of the animation
Can either be percentages between 0-100% or in the case of animations with only two waypoints, the keywords “from” and “to.”
[CSS properties]: the CSS properties that change throughout the animation. Not all CSS properties are “animatable.”
A detailed list of which properties are and are not able to be animated is located here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
.box {
animation-duration: 1s;
animation-name: zoom-pulse;
animation-iteration-count: infinite;
}
@keyframes zoom-pulse {
0% { transform: rotate(-9deg) scale(0.8); }
17% { transform: rotate(-3deg) scale(1); }
34% { transform: rotate(3deg) scale(1.2); }
51% { transform: rotate(9deg) scale(1.4); }
68% { transform: rotate(3deg) scale(1.2); }
85% { transform: rotate(-3deg) scale(1); }
100% { transform: rotate(-9deg) scale(0.8); }
}
animation-name: none;
animation-duration: 0s;
animation-timing-function: ease;
animation-delay: 0s;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: none;
animation-play-state: running;
http://bethsoderberg.com/slides/2015/wordcamp-lancaster/index.html