8000 csswg-drafts/css3-transforms/Transforms.src.html at 5fe2220dd1a1c097f0bc39a329e37a3ebd952afc · xfq/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
2698 lines (2464 loc) · 128 KB

File metadata and controls

2698 lines (2464 loc) · 128 KB
<!DOCTYPE html public '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html lang="en">
<head profile="http://www.w3.org/2006/03/hcard">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSS Transforms</title>
<link rel="stylesheet" type="text/css" href="../default.css" />
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" />
<script src='http://test.csswg.org/harness/annotate.js#CSS3-TRANSFORMS_DEV' type='text/javascript' defer></script>
<style type="text/css">
.term {
font-style: italic;
}
.todo {
font-weight: bold;
border-left: 0.5em solid #f44;
padding-left: 1em;
margin-top: 0.5em;
color: #a0a0a0;
}
.todo:before {
content: "TO DO : ";
color: #f44;
}
</style>
</head>
<body>
<div id="div-head" class="head">
<!--logo-->
<h1>CSS Transforms</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:
<dd>
<a href="[VERSION]">http://dev.w3.org/csswg/css3-transforms/</a>
<!--http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]/-->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-transforms/">[LATEST]</a>
<dt>Editor's draft:
<dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
<dt>Previous versions:
<dd><a href='http://www.w3.org/TR/2012/WD-css3-transforms-20120228/'>http://www.w3.org/TR/2012/WD-css3-transforms-20120228/</a>
<dt id="editors-list">Editors:
<dd>Simon Fraser (<a href="http://www.apple.com/">Apple Inc</a>) &lt;simon.fraser &#64;apple.com&gt;
<dd>Dean Jackson (<a href="http://www.apple.com/">Apple Inc</a>) &lt;dino &#64;apple.com&gt;
<dd>David Hyatt (<a href="http://www.apple.com/">Apple Inc</a>) &lt;hyatt &#64;apple.com&gt;
<dd>Chris Marrin (<a href="http://www.apple.com/">Apple Inc</a>) &lt;cmarrin &#64;apple.com&gt;
<dd>Edward O'Connor (<a href="http://www.apple.com/">Apple Inc</a>) &lt;eoconnor &#64;apple.com&gt;
<dd>Dirk Schulze (<a href="http://www.adobe.com/">Adobe Systems, Inc</a>) &lt;dschulze &#64;adobe.com&gt;
<dd>Aryeh Gregor (<a href="http://www.mozilla.org/">Mozilla</a>) &lt;ayg &#64;aryeh.name&gt;
<dt>Issues list:
<dd><a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&amp;product=CSS&amp;component=Transforms&amp;resolution=---&amp;cmdtype=doit">in Bugzilla</a>
<dt>Test suite:
<dd>none yet
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>CSS transforms allows elements styled with CSS to be transformed
in two-dimensional or three-dimensional space. This specification is the convergence of the
<a href="http://www.w3.org/TR/css3-2d-transforms/">CSS 2D transforms</a>,
<a href="http://www.w3.org/TR/css3-3d-transforms/">CSS 3D transforms</a>
and <a href="http://www.w3.org/TR/2009/WD-SVG-Transforms-20090320/">SVG transforms</a>
specifications.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>
This specification replaces the former <a href="http://www.w3.org/TR/css3-2d-transforms/" title="CSS 2D Transforms">CSS 2D Transforms</a> and <a href="http://www.w3.org/TR/css3-3d-transforms/" title="CSS 3D Transforms Module Level 3">CSS 3D Transforms</a> specifications, as well
as <a href="http://www.w3.org/TR/SVG-Transforms/" title="SVG Transforms 1.0">SVG Transforms</a>.
</p>
<p>
The <a href="ChangeLog">list of changes made to this specification</a> is
available.
</p>
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2>Introduction</h2>
<p><em>This section is not normative.</em></p>
<p>
The CSS <a href="http://www.w3.org/TR/REC-CSS2/visuren.html">visual
formatting model</a> describes a coordinate system within each
element is positioned. Positions and sizes in this coordinate space can
be thought of as being expressed in pixels, starting in the origin of point
with positive values proceeding to the right and down.
</p>
<p>
This coordinate space can be modified with the 'transform' property. Using transform,
elements can be translated, rotated and scaled in two or three dimensional space.
</p>
<p>
Additional properties make working with transforms easier, and allow the
author to control how nested three-dimensional transforms interact.
</p>
<ul>
<li>
The 'transform-origin' property provides a convenient way to control the origin about
which transforms on an element are applied.
</li>
<li>
The 'perspective' property allows the author to make child elements with
three-dimensional transforms appear as if they live in a common three-dimensional
space.
The 'perspective-origin' property provides control over the origin at which
perspective is applied, effectively changing the location of the "vanishing point".
</li>
<li>
The 'transform-style' property allows 3D-transformed elements and their 3D-transformed
descendants to share a common three-dimensional space, allowing the construction of
hierarchies of three-dimensional objects.
</li>
<li>
The 'backface-visibility' property comes into play when an element is flipped around
via three-dimensional transforms such that its reverse side is visible to the viewer.
In some situations it is desirable to hide the element in this situation, which is
possible using the value of ''hidden'' for this property.
</li>
</ul>
<p>
Note that while some values of the 'transform' property allow an element to be
transformed in a three-dimensional coordinate system, the elements themselves are not
three-dimensional objects. Instead, they exist on a two-dimensional plane (a flat
surface) and have no depth.
</p>
<!-- ======================================================================================================= -->
<h2 id="module-interactions">Module Interactions</h2>
<p>This module defines a set of CSS properties that affect the visual rendering of elements to which
those properties are applied; these effects are applied after elements have been sized and positioned according
to the <a href="http://www.w3.org/TR/CSS2/visuren.html" title="Visual formatting model">Visual formatting model</a>
from [[!CSS21]]. Some values of these properties result in the creation of a <a href="http://www.w3.org/TR/CSS2/visuren.html#containing-block" title="Visual formatting model">containing block</a>, and/or the creation of a <a href="http://www.w3.org/TR/CSS2/visuren.html#z-index" title="Visual formatting model">stacking context</a>.
</p>
<p>
Three-dimensional transforms can also affect the visual layering of elements, and thus override the back-to-front
painting order described in <a href="http://www.w3.org/TR/CSS2/zindex.html" title="Elaborate description of Stacking Contexts">Appendix E</a> of [[!CSS21]].
</p>
<!-- Probably need more here. -->
<h2 id="css-values">CSS Values</h2>
<p>This specification follows the <a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].</p>
<p>In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the <a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a> keyword as their property value. For readability it has not been repeated explicitly.
<h2 id="definitions">Definitions</h2>
<p> When used in this specification, terms have the meanings assigned in
this section.
</p>
<dl>
<dt id="TermBoundingBox"><dfn>bounding box</dfn></dt>
<dd>
<p>
A bounding box is the object bounding box for all SVG elements
without an associated CSS layout box and the border box for all
other elements. The bounding box of a table is the border box
of its
<a href="http://www.w3.org/TR/CSS21/tables.html#model">table wrapper box</a>,
not its table box.
</p>
</dd>
<dt id="TermTransformableElement"><dfn>transformable element</dfn></dt>
<dd>
<p>
A transformable element is an element in the HTML namespace
which is either a
<a href="http://www.w3.org/TR/CSS2/visuren.html#block-level">block-level</a>
or
<a href="http://www.w3.org/TR/CSS2/visuren.html#x13">atomic inline-level element</a>,
or whose '<code class="property">display</code>' property
computes to '<code class="css">table-row</code>',
'<code class="css">table-row-group</code>',
'<code class="css">table-header-group</code>',
'<code class="css">table-footer-group</code>',
'<code class="css">table-cell</code>', or
'<code class="css">table-caption</code>'; or an element in the
SVG namespace (see [[SVG11]]) which has the attributes
'<code class="property">transform</code>', 'patternTransform'
or 'gradientTransform'.
</p>
</dd>
<dt id="TermPerspectiveMatrix"><dfn>perspective matrix</dfn></dt>
<dd>
<p>
A matrix computed from the values of the '<code class="property">perspective</code>' and '<code class="property">perspective-origin</code>' properties as described <a href="#perspective-matrix-computation">below</a>.
</p>
</dd>
<dt id="TermTransformationMatrix"><dfn>transformation matrix</dfn></dt>
<dd>
<p>
A matrix computed from the values of the '<code class="property">transform</code>' and '<code class="property">transform-origin</code>' properties as described <a href="#transformation-matrix-computation">below</a>.
</p>
</dd>
<dt id="TermAccumulated3DTransformationMatrix">
<dfn>accumulated 3D transformation matrix</dfn>
</dt>
<dd>
<p>
A matrix computed for elements in a
<a href="#d-rendering-context">3D rendering context</a>, as
described
<a href="#accumulated-3d-transformation-matrix-computation">below</a>.
</p>
</dd>
<dt id="TermIdentityTransformFunction">
<dfn>Identity transform function</dfn>
</dt>
<dd>
<p>
A <a href="#transform-functions">transform function</a> that is equivalent to a
identity 4x4 matrix (see <a href="#mathematical-description">Mathematical
Description of Transform Functions</a>). Examples for identity transform functions
are ''translate(0)'', ''translate3d(0, 0, 0)'', ''translateX(0)'',
''translateY(0)'', ''translateZ(0)'', ''scale(1)'', ''scaleX(1)'', ''scaleY(1)'',
''scaleZ(1)'', ''rotate(0)'', ''rotate3d(1, 1, 1, 0)'', ''rotateX(0)'',
''rotateY(0)'', ''rotateZ(0)'', ''skewX(0)'', ''skewY(0)'', ''matrix(1, 0, 0, 1, 0,
0)'' and ''matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)''. A special
case is perspective: ''perspective(infinity)''. The value of m<small>34</small>
becomes infinitesimal small and the transform function is therefore assumed to be
equal to the identity matrix.
</p>
</dd>
<dt id="Term3DRenderingContext"><dfn>3D rendering context</dfn></dt>
<dd>
<p>
A containing block hierarchy of one or more levels, instantiated by elements with a computed value for
the '<code class="property">transform-style</code>' property of '<code class="css">preserve-3d</code>',
whose elements share a common three-dimensional coordinate system.
</p>
</dd>
</dl>
<!-- ======================================================================================================= -->
<h2 id="two-dimensional-subset">
Two Dimensional Subset
</h2>
<p>
UAs may not always be able to render three-dimensional transforms and then just
support a two-dimensional subset of this specification. In this case <a
href="#three-d-transform-functions">three-dimensional transforms</a> and the
properties 'transform-style', 'perspective', 'perspective-origin' and
'backface-visibility' must not be supported. Section <a
href="#transform-3d-rendering">3D Transform Rendering</a> does not apply.
Matrix decomposing uses the technique taken from the "unmatrix" method in "Graphics
Gems II, edited by Jim Arvo", simplified for the 2D case. Section
<a href="#mathematical-description">Mathematical Description of Transform
Functions</a> is still effective but can be reduced by using a 3x3
transformation matrix where <em>a</em> equals <em>m11</em>, <em>b</em> equals
<em>m12</em>, <em>c</em> equals <em>m21</em>, <em>d</em> equals <em>m22</em>,
<em>e</em> equals <em>m41</em> and <em>f</em> equals <em>m42</em> (see <a
href="#MatrixDefined">A 2D 3x2 matrix with six parameter</a>).
</p>
<div class="figure">
<img src="3x3matrix.png" alt="3x3 matrix" title="\begin{bmatrix} a & c & e \\ b
& d & f \\ 0 & 0 & 1 \end{bmatrix}" width="82" height="79">
<p class="caption">
3x3 matrix for two-dimensional transformations.
</p>
</div>
<div class="example">
<p>
Authors can easily provide a fallback if UAs do not provide support for
three-dimensional transforms. The following example has two property definitions
for 'transform'. The first one consists of two two-dimensional transform
functions. The second one has a two-dimensional and a three-dimensional transform
function.
</p>
<pre>div {
transform: scale(2) rotate(45deg);
transform: scale(2) rotate3d(0, 0, 1, 45deg);
}</pre>
<p>
With 3D support, the second definition will override the first one. Without 3D
support, the second definition is invalid and a UA falls back to the first
definition.
</p>
</div>
<!-- ======================================================================================================= -->
<h2 id="transform-rendering">The Transform Rendering Model</h2>
<!-- This section is normative -->
<p>
Specifying a value other than ''none'' for the ''transform'' property establishes a new
<em>local coordinate system</em> at the element that it is applied to. The mapping from
where the element would have rendered into that local coordinate system is given by the
element's <a href="#TermTransformationMatrix"><i>transformation matrix</i></a>.
Transformations are cumulative. That is, elements establish their local coordinate
system within the coordinate system of their parent. From the perspective of the user,
an element effectively accumulates all the 'transform' properties of its ancestors as
well as any local transform applied to it. The accumulation of these transforms defines
a <em>current transformation matrix (CTM)</em> for the element.
</p>
<p>
The coordinate space behaves as described in the <a
href="http://www.w3.org/TR/SVG/coords.html#EstablishingANewUserSpace">coordinate
system transformations</a> section of the SVG 1.1 specification. This is a
coordinate system with two axes: the X axis increases horizontally to the right; the
Y axis increases vertically downwards. Three-dimensional transform functions extent
this coordinate space into three dimensions, adding a Z axis perpendicular to the
plane of the screen, that increases towards the viewer.
</p>
<p id="transformation-matrix-computation">
The <a href="#TermTransformationMatrix"><i>transformation matrix</i></a> is computed
from the 'transform' and 'transform-origin' properties as follows:
<ol>
<li>Start with the identity matrix.</li>
<li>Translate by the computed X, Y and Z values of 'transform-origin'</li>
<li>Multiply by each of the transform functions in 'transform' property in turn</li>
<li>Translate by the negated computed X, Y and Z values of 'transform-origin'</li>
</ol>
</p>
<p>
Transforms apply to <span class="term">transformable elements</span>.
</p>
<div class="example">
<pre>
div {
transform: translate(100px, 100px);
}
</pre>
<p>This transform moves the element by 100 pixels in both the X and Y directions.</p>
<div class="figure">
<img src="examples/translate1.svg" alt="The 100px translation in X and Y"
width="470" height="250">
</div>
</div>
<div class="example">
<pre>div {
height: 100px; width: 100px;
transform-origin: 50px 50px;
transform: rotate(45deg);
}</pre>
<p>
The 'transform-origin' property moves the point of origin by 50 pixels in both
the X and Y directions. The transform rotates the element clockwise by 45° about
the point of origin. After all transform functions were applied, the translation
of the origin gets translated back by -50 pixels in both the X and Y directions.
</p>
<div class="figure">
<img alt="The point of origin gets translated temporary" src="examples/origin1.svg"
width="735" height="250">
</div>
</div>
<div class="example">
<pre>
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
</pre>
<p>
This transform moves the element by 80 pixels in both the X and Y directions, then
scales the element by 150%, then rotates it 45&deg; clockwise about the Z axis.
Note that the scale and rotation operate about the center of the element, since
the element has the default transform-origin of ''50% 50%''.
</p>
<div class="figure">
<img src="examples/compound_transform.svg" alt="The transform specified above"
width="270" height="270">
</div>
<p>
Note that an identical rendering can be obtained by nesting elements with the
equivalent transforms:
</p>
<pre>
&lt;div style="transform: translate(80px, 80px)"&gt;
&lt;div style="transform: scale(1.5, 1.5)"&gt;
&lt;div style="transform: rotate(45deg)"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</pre>
</div>
<!-- This "in the HTML namespace" is awkward. Is there a better way? -->
<p>
In the HTML namespace, the transform property does not affect the flow of the
content surrounding the transformed element. However, the extent of the overflow
area takes into account transformed elements. This behavior is similar to what
happens when elements are offset via relative positioning. Therefore, if the value
of the 'overflow' property is ''scroll'' or ''auto'', scrollbars will appear as
needed to see content that is transformed outside the visible area.
</p>
<p>
In the HTML namespace, any value other than ''none'' for the transform results in
the creation of both a stacking context and a containing block. The object acts as a
containing block for fixed positioned descendants.
</p>
<p class="issue">
Is this effect on position:fixed necessary? If so, need to go into more detail here
about why fixed positioned objects should do this, i.e., that it's much harder to
implement otherwise.
</p>
<p>
<a href="http://dev.w3.org/csswg/css3-background/#fixed0">Fixed backgrounds</a>
are affected by any transform specified for the root element, and not by any other
transforms.
</p>
<p class="note">
Thus an element with a fixed background still acts like a
"porthole" into an image that's fixed to the viewport, and
transforms on the element affect the porthole, not the
background behind it. On the other hand, transforming the root
element will still transform everything on the page, rather
than everything except for fixed backgrounds.
</p>
<p>
If the root element is transformed, the transformation applies
to the entire canvas, including any background specified for
the root element. Since
<a href="http://dev.w3.org/csswg/css3-background/#special-backgrounds">the
background painting area for the root element</a> is the entire
canvas, which is infinite, the transformation might cause parts
of the background that were originally off-screen to appear.
For example, if the root element's background were repeating
dots, and a transformation of
''scale(0.5)'' were specified on the
root element, the dots would shrink to half their size, but
there will be twice as many, so they still cover the whole
viewport.
</p>
<h3 id="transform-3d-rendering">3D Transform Rendering</h3>
<!-- Maybe define "tranform container" in the definitions, and use it everywhere
in place of "containing block"? I'm not sure if "containing block" is exactly right. -->
<p>
Normally, elements render as flat planes, and are rendered into the same plane
as their containing block. Often this is the plane shared by the rest of the page.
Two-dimensional transform functions can alter the appearance of an element, but
that element is still rendered into the same plane as its containing block.
</p>
<p>
Three-dimensional transforms can result in transformation matrices with a non-zero
Z component<!-- clarify -->, potentially lifting them off the plane of their
containing block. Because of this, elements with three-dimensional transformations
could potentially render in an front-to-back order that different from the normal CSS rendering order,
and intersect with each other. Whether they do so depends on whether the element is a member
of a <span class="term">3D rendering context</span>, as described below.
</p>
<div class="issue">
<p class="desc">This description does not exactly match what WebKit implements. Perhaps
it should be changed to match current implementations?</p>
</div>
<div class="example">
<p>This example shows the effect of three-dimensional transform applied to an element.
</p>
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<div class="figure">
<img src="examples/simple-3d-example.png" width="210" height="190" alt="Div with a rotateY transform.">
</div>
<p>The transform is a 50&deg; rotation about the vertical, Y axis. Note how this makes the blue box appear
narrower, but not three-dimensional.
</p>
</div>
<p>
The '<code class="property">perspective</code>' and
'<code class="property">perspective-origin</code>'
properties can be used to add a feeling of depth to a
scene by making elements higher on the Z axis (closer to
the viewer) appear larger, and those further away to
appear smaller. The scaling is proportional to
<var>d</var>/(<var>d</var> &minus; <var>Z</var>)
where <var>d</var>, the value of
'<code class="property">perspective</code>', is the
distance from the drawing plane to the the assumed
position of the viewer's eye.
</p>
<div class="figure">
<img alt="Diagram of scale vs. Z position" src="perspective_distance.png">
<p class="caption">
Diagrams showing how scaling depends on the
'<code class="property">perspective</code>' property
and Z position. In the top diagram, <var>Z</var> is half of <var>d</var>. In
order to make it appear that the original circle
(solid outline) appears at <var>Z</var> (dashed
circle), the circle is scaled up by a factor of two,
resulting in the light blue circle. In the bottom
diagram, the circle is scaled down by a factor of
one-third to make it appear behind the original
position.
</p>
</div>
<p>
Normally the assumed position of the viewer's eye is
centered on a drawing. This position can be moved if
desired &ndash; for example, if a web page contains
multiple drawings that should share a common perspective
&ndash; by setting
'<code class="property">perspective-origin</code>'.
</p>
<div class="figure">
<img alt="Diagram of different perspective-origin" src="perspective_origin.png">
<p class="caption">
Diagram showing the effect of moving the perspective origin upward.
</p>
</div>
<p id="perspective-matrix-computation">
The <a href="#TermPerspectiveMatrix"><i>perspective matrix</i></a> is computed as follows:
<!-- Make this more mathy, with matrices? -->
<ol>
<li>Start with the identity matrix.</li>
<li>Translate by the computed X and Y values of '<code class="property">perspective-origin</code>'</li>
<li>Multiply by the matrix that would be obtained from the '<a href="#perspective-function"><code class="css">perspective(&lt;length&gt;)</code></a>' transform function, where the length is provided by the value of the '<code class="property">perspective</code>' property</li>
<li>Translate by the negated computed X and Y values of '<code class="property">perspective-origin</code>'</li>
</ol>
</p>
<div class="example">
<p>This example shows how perspective can be used to cause three-dimensional transforms to appear more realistic.
</p>
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<div class="figure">
<img src="examples/simple-perspective-example.png" width="210" height="190" alt="Div with a rotateY transform,
and perspective on its container">
</div>
<p>The inner element has the same transform as in the previous example, but its rendering is now influenced by the perspective
property on its parent element. Perspective causes vertices that have positive Z coordinates (closer to the viewer)
to be scaled up in X and Y, and those further away (negative Z coordinates) to be scaled down, giving an appearance of depth.
</p>
</div>
<p>
An element with a three-dimensional transform that is not contained in a
<span class="term">3D rendering context</span> renders with the appropriate
transform applied, but does not intersect with any other elements. The three-dimensional
transform in this case can be considered just as a painting effect, like two-dimensional
transforms. Similarly, the transform does not affect painting order. For example, a transform with a
positive Z translation may make an element look larger, but does not cause that element
to render in front of elements with no translation in Z.
</p>
<p>
An element with a three-dimensional transform that is contained in a
<span class="term">3D rendering context</span> can visibly interact with other elements
in that same 3D rendering context; the set of elements participating in the same
<span class="term">3D rendering context</span> may obscure each other or intersect,
based on their computed transforms. They are rendered as if they are all siblings,
positioned in a common 3D coordinate space. The position of each element in that three-dimensional
space is determined by accumulating the transformation matrices
up from the element that establishes the <span class="term">3D rendering context</span>
through each element that is a containing block for the given element, as described below.
<!-- More detail required, probably with matrices -->
</p>
<div class="example">
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
transform: rotateY(50deg);
background-color: blue;
}
.child {
transform-origin: top left;
transform: rotateX(40deg);
background-color: lime;
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div class="transformed"&gt;
&lt;div class="child"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>This example shows how nested 3D transforms are rendered in the absence of '<code class="css">transform-style: preserve-3d</code>'. The blue div is transformed as in the previous example, with its rendering influenced by the perspective on its parent element. The lime element also has a 3D transform, which is a rotation about the X axis (anchored at the top, by virtue of the transform-origin). However, the lime element is being rendered into the plane of its parent because it is not a member of a 3D rendering context; the parent is "flattening".
</p>
<div class="figure">
<img src="examples/3d-rendering-context-flat.png" width="240" height="200" alt="Nested 3D transforms, with flattening">
</div>
</div>
<p>Elements establish and participate in 3D rendering contexts as follows:</p>
<ul>
<li>
A <span class="term">3D rendering context</span> is established by a
a <span class="term">transformable element</span> whose computed value for '<code class="property">transform-style</code>' is
'<code class="css">preserve-3d</code>', and which itself is not part of a 3D rendering context.
Note that such an element is always a containing block. An element that establishes a 3D rendering context
also participates in that context.
</li>
<li>
An element whose computed value for '<code class="property">transform-style</code>' is
'<code class="css">preserve-3d</code>', and which itself participates in a
<span class="term">3D rendering context</span>, extends that 3D rendering context rather than establishing
a new one.
</li>
<li>
An element participates in a <span class="term">3D rendering context</span> if its containing block
establishes or extends a <span class="term">3D rendering context</span>.
</li>
</ul>
<p id="accumulated-3d-transformation-matrix-computation">
The final value of the transform used to render an element in a <span class="term">3D rendering context</span>
is computed by accumulating an
<a href="#TermAccumulated3DTransformationMatrix">
accumulated 3D transformation matrix</a> as follows:
</p>
<ol>
<li>Start with the identity matrix.</li>
<li>For each containing block between the root of the <span class="term">3D rendering context</span>
and the element in question:
<ol>
<li>multiply the accumulated matrix with the <a href="#TermPerspectiveMatrix"><i>perspective matrix</i></a>
on the element's containing block (if any). That containing block is not necessarily a member
of the 3D rendering context.</li>
<li>apply to the accumulated matrix a translation equivalent to the horizontal and vertical offset of the element relative to
its containing block as specified by the CSS visual formatting model. <!-- (tighten this!) --></li>
<li>multiply the accumulated matrix with the <a href="#TermTransformationMatrix"><i>transformation matrix</i></a>.</li>
</ol>
</li>
</ol>
<div class="example">
<pre>
&lt;style&gt;
div {
height: 150px;
width: 150px;
}
.container {
perspective: 500px;
border: 1px solid black;
}
.transformed {
<b>transform-style: preserve-3d</b>;
transform: rotateY(50deg);
background-color: blue;
}
.child {
transform-origin: top left;
transform: rotateX(40deg);
backgr 28A5 ound-color: lime;
}
&lt;/style&gt;
</pre>
<p>This example is identical to the previous example, with the addition of '<code class="css">transform-style: preserve-3d</code>' on the blue element. The blue element now establishes a 3D rendering context, of which the lime element is a member. Now both blue and lime elements share a common three-dimensional space, so the lime element renders as tilting out from its parent, influenced by the perspective on the container.
</p>
<div class="figure">
<img src="examples/3d-rendering-context-3d.png" width="240" height="200" alt="Nested 3D transforms, with preserve-3d.">
</div>
</div>
<p>
Elements in the same <span class="term">3D rendering context</span> may intersect with each other. User agents must
render intersection by subdividing the planes of intersecting elements as described by
<a href="http://en.wikipedia.org/wiki/Newell's_algorithm">Newell's algorithm</a>.
</p>
<p>
Untransformed elements in a <span class="term">3D rendering context</span> render on the Z=0 plane, yet may still
intersect with transformed elements.
</p>
<p>
Within a <span class="term">3D rendering context</span>, the rendering order of non-intersecting elements is
based on their position on the Z axis after the application of the accumulated transform. Elements at the same
Z position render in <a href="http://www.w3.org/TR/CSS2/zindex.html#painting-order">stacking context order</a>.
</p>
<div class="example">
<pre>
&lt;style&gt;
.container {
background-color: rgba(0, 0, 0, 0.3);
transform-style: preserve-3d;
perspective: 500px;
}
.container > div {
position: absolute;
left: 0;
}
.container > :first-child {
transform: rotateY(45deg);
background-color: orange;
top: 10px;
height: 135px;
}
.container > :last-child {
transform: translateZ(40px);
background-color: rgba(0, 0, 255, 0.75);
top: 50px;
height: 100px;
}
&lt;/style&gt;
&lt;div class="container"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>
This example shows show elements in a 3D rendering context can intersect. The container element establishes
a 3D rendering context for itself and its two children. The children intersect with eachother, and
the orange element also intersects with the container.
</p>
<div class="figure">
<img src="examples/3d-intersection.png" width="200" height="200" alt="Intersecting sibling elements.">
</div>
</div>
<p>
Using three-dimensional transforms, it's possible to transform an element such that its reverse side
is towards the viewer. 3D-tranformed elements show the same content on both sides, so the reverse side
looks like a mirror-image of the front side (as if the element were projected onto a sheet of glass).
Normally, elements whose reverse side is towards the viewer remain visible. However, the
'<code class="property">backface-visibility</code>' property allows the author to make an element invisible
when its reverse side is towards the viewer. This behavior is "live"; if an element with
'<code class="css">backface-visibility: hidden</code>' were animating,
such that its front and reverse sides were alternately visible, then it would only be visible when the
front side were towards the viewer.
</p>
<!-- ======================================================================================================= -->
<h2 id="transform-property">
The '<code class="property">transform</code>' Property
</h2>
<p>
A transformation is applied to the coordinate system an element
renders in through the '<code class="property">transform</code>' property. This property contains a
list of <a href="#transform-functions">transform functions</a>. The
final transformation value for a coordinate system is obtained by converting
each function in the list to its corresponding matrix like defined in <a href="#mathematical-description">Mathematical
Description of Transform Functions</a>, then multiplying the matrices.
</p>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="effects">transform</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
none | &lt;transform-function&gt; [ &lt;transform-function&gt; ]*
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
none
</td>
</tr>
<tr>
<td>
<em>Applies&nbsp;to:</em>
</td>
<td>
<a href="#TermTransformableElement">transformable elements</a>
</td>
</tr>
<tr>
<td>
<em>Inherited:</em>
</td>
<td>
no
</td>
</tr>
<tr>
<td>
<em>Percentages:</em>
</td>
<td>
refer to the size of the element's
<a href="#TermBoundingBox">bounding box</a>
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
As specified, but with relative lengths converted into
absolute lengths.
</td>
</tr>
</tbody>
</table>
<p>Any value other than '<code class="css">none</code>' for the transform results in the creation of both a stacking context and a containing block. The object acts as a containing block for fixed positioned descendants.</p>
<!-- ======================================================================================================= -->
<h2 id="transform-origin-property">
The '<code class="property">transform-origin</code>' Property
</h2>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="transform-origin">transform-origin</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
[ &lt;percentage> | &lt;length> | left | center | right | top | bottom]<br>
|<br>
[<br>
&nbsp;&nbsp;[ &lt;percentage> | &lt;length&gt; | left | center | right ]<br>
&nbsp;&nbsp;&amp;&amp;<br>
&nbsp;&nbsp;[ &lt;percentage> | &lt;length&gt; | top | center | bottom ]<br>
] &lt;length&gt;?<br>
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
50% 50%
</td>
</tr>
<tr>
<td>
<em>Applies&nbsp;to:</em>
</td>
<td>
<a href="#TermTransformableElement">transformable elements</a>
</td>
</tr>
<tr>
<td>
<em>Inherited:</em>
</td>
<td>
no
</td>
</tr>
<tr>
<td>
<em>Percentages:</em>
</td>
<td>
refer to the size of the element's
<a href="#TermBoundingBox">bounding box</a>
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
For &lt;length&gt; the absolute value, otherwise a percentage
</td>
</tr>
</tbody>
</table>
<p>
The default value for SVG elements without associated CSS layout box is ''0 0''.
</p>
<p>
The values of the 'transform' and 'transform-origin' properties are used to compute
the <a href="#TermTransformationMatrix"><i>transformation matrix</i></a>, as
described above.
</p>
<p>
If only one value is specified, the second value is assumed to be ''center''. If one
or two values are specified, the third value is assumed to be ''0px''.
</p>
<p>
If two or more values are defined and either no value is a keyword, or the only
used keyword is ''center'', then the first value represents the horizontal position
(or offset) and the second represents the vertical position (or offset). A third
value always represents the Z position (or offset) and must be of type
<var>&lt;length&gt;</var>.
</p>
<p>
<var>&lt;percentage&gt;</var> and <var>&lt;length&gt;</var> for the first two values
represent an offset of the transform origin from the top left corner of the element's
<a href="#TermBoundingBox">bounding box</a>.
</p>
<p>
For SVG elements without an associated CSS layout box the <var>&lt;length&gt;</var>
values represent an offset from the point of origin of the element's local
coordinate space.
</p>
<p>