transform-origin
skew()
matrix3d()
perspective
Propertyperspective()
function v. perspective
propertytransform-origin
propertytransform-style
Propertybackface-visibility
Propertytransform-box
propertytransform: none | <transFunc()> [<transFunc()>];
transform: translate(300px, 90px) rotate(50deg) scale(0.7, 0.9) skewX(15deg);
We'll cover more in a bit....
Only transformable elements can be transformed.
display: inline-block;
on inline elementstransform: translate(100px, 100px);
transform: translateX(100px);
transform: translateY(100px);
Edit a value to set it. Mouse out of a value to see it.
transform: translate()
Remove the underscores to activate.
rotate()
transform: rotate(90deg);
Edit the value to set it. Mouse out to see it.
transform: rotate(90deg);
transform: rotateX(90deg);
transform: rotateY(90deg);
Edit the value to set it. Mouse out to see it.
transform: rotate()
Remove the underscores to activate.
transform-origin
propertytransform-origin: <x-offset> [ <y-offset>? ] [ <z> ]?;
transform-origin: 50% 50% 0;
<length>, <percentage>
or the left | center | right
<length>, <percentage>
or the top | center | bottom
center
, and Z = 0
.y = center
and Z = 0
.<Z>
can only be a length, defaulting to 0 if omitted.transform-origin
propertyRemove the underscores to activate. Change the transform-origin value
scale()
transform: scale(0.25, 0.75);
transform: scale(0.75);
transform: scaleX(0.25);
transform: scaleY(0.75);
Edit a value to set it. Mouse out of a value to see it.
transform: scale()
& transform-origin
Remove the underscores to activate. Change the transform-origin value
skew()
skew()
transform: skewX(5deg);
transform: skewY(5deg);
transform: skewX(5deg) skewY(5deg);
transform: skew(5deg,5deg);
Edit a value to set it. Mouse out of a value to see it.
skew()
Remove the underscore to activate the CSS
transform: skew()
& transform-origin
Remove the underscore to activate the CSS
transform-origin
matrix()
matrix(a, b, c, d, tx, ty)
shorthand
formatrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1)
(which makes no
sense).
Computer generated transform.
transform: matrix(a, b, c, d, tx, ty)
Order of transform functions matters: if you rotate first, your translate direction will be on the rotated axis!
translateX(200px)
rotate(135deg)
transform-origin
transform: translateZ()
Remove the underscores to activate.
transform: perspective()
transform: perspective()
& translateZ()
Remove the underscores to activate.
transform: translate3d()
Remove the underscores to activate.
translateZ( <length> )
Specifies a 3D translation by the vector [0, 0, tz].
translate3d( <length-percent> , <length-percent> , <length> )
Specifies a 3D translation by the vector [tx, ty, tz], in that order.
translateZ( 200px ) == translate3d( 0, 0, 200px )
scaleZ( <number> )
Specifies a 3D scale operation using the [1, 1, sz] scaling vector, where sZ is the parameter.
scale3d( <number> , <number>, <number> )
Specifies a 3D scale operation by the [sx, sy, sz] scaling vector described by the 3 parameters.
scaleZ( 0.7 ) == scale3d( 1, 1, 0.7 )
rotate3d( <number> , <number> , <number> , <angle> )
Specifies a 3D rotation by the angle specified in last parameter about the [x,y,z] direction vector described by the first three parameters. The angle can be zero.
rotateX( <angle> )
rotateY( <angle> )
Same as rotate3d(1, 0, 0, <angle>)
or
rotate3d(0, 1, 0, <angle>)
, respectively. Angle can be zero.
rotateZ( <angle> )
same as rotate3d(0, 0, 1, <angle>)
, which is a 3d transform equivalent to the 2d transform
rotate(<angle>)
. Angle can be zero.
transform: rotate3d()
Remove the underscores to activate.
matrix3d( <number>#{16} )
specifies a 3D transformation as a matrix of 16 values
matrix(a, b, c, d, tx, ty)
is a shorthand for
matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1)
.
matrix(-0.5, 1, 1, -0.5, 20, 20) matrix(-0.5, 1, 0, 0, 1, -0.5, 0, 0, 0, 0, 1, 0, 20, 20, 0, 1)
transform: matrix3d()
perspective( <length> )
The parameter is the distance of the z=0 plane from the viewer.
Must be greater than zero!
transforms: perspective(value)
except it applies to the positioned or transformed
children of the element, not the element itself.transform: perspective(100) ...
perspective: 100
Difference: with the parent property, all the transformed elements share the same perspective. with the function, each transformed element has it's own perspective.
perspective()
transform: perspective(40px) rotateX(10deg);
The perspective()
function must come first
Smaller numbers have a bigger impact
perspective
PropertyEdit the above to see what happens.
Edit the previous slide via devTools
Click 'shift' on angles to change the format.
Hover over a transform property in the Rules view to see the transformation overlaid on the page (note: this doesn't work quite right on generated content)
transform: perspective(400px)
v. perspective: 400px
transform: perspective(400px)
on children
perspective: 400px
on parent
perspective-origin
perspective-origin: x y
perspective
property. perspective
propertyperspective-origin
Propertyperspective-origin
with perspective: 400px
perspective-origin: 0 0
on parent
only works if perspective
is on that parent!
perspective-origin
Propertytransform-origin
propertySpecifies the x and y position of the origin, relative to the transform object.
transform-origin
propertychange the values
transform-style
transform-style
PropertyChild
transform-style
Propertytransform-style
Propertybackface-visibility
PropertyHere's where all the magic happens! Let's make all the cards slightly off-center so each can be hovered individually. We hide the face of the cards, making the card flip, making the face visible on hover but the back disappear.
In the next section, we'll and a transition, to make the flip / motion visible.
HTML | CSS.card { perspective: 600px; } .card .front { transform: rotateX(0deg) rotateY(0deg); transform-style: preserve-3d; backface-visibility: hidden; }/* non-hovered card */ .card:first-of-type { transform: rotate(-10deg); } .card:nth-of-type(2) { transform: rotate(15deg) translatex(5px); } .card:last-of-type { transform: rotate(0deg); } /* on hover */ .card:first-of-type:hover { transform: translatex(-200px) rotate(10deg); } .card:nth-of-type(2):hover { transform: translatex(200px) rotate(0); } .card:last-of-type:hover { transform: translatey(200px) rotate(5deg); } /* cardFlip */ .card:hover .front { transform: rotateY(0); } .card:hover .back { transform: rotateY(180deg); box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2); }
transform-box
propertyDefines the layout box, to which the transform
and transform-origin
properties
relate to.
content-box | border-box | fill-box | stroke-box | view-box
content-box
border-box
fill-box
stroke-box
view-box
viewBox
attribute exists, the reference box is at
the viewBox
0 0, and the width and height are those of the viewBox
attribute.
transform-box
propertycontent-box | border-box | fill-box | stroke-box | view-box
change the values