forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransforms.src.html
More file actions
2045 lines (1908 loc) · 97.6 KB
/
Transforms.src.html
File metadata and controls
2045 lines (1908 loc) · 97.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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" />
<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>Previous version:
<dd>None
<dt id="editors-list">Editors:
<dd>Simon Fraser (<a href="http://www.apple.com/">Apple Inc</a>) <simon.fraser @apple.com>
<dd>Dean Jackson (<a href="http://www.apple.com/">Apple Inc</a>) <dino @apple.com>
<dd>David Hyatt (<a href="http://www.apple.com/">Apple Inc</a>) <hyatt @apple.com>
<dd>Chris Marrin (<a href="http://www.apple.com/">Apple Inc</a>) <cmarrin @apple.com>
<dd>Edward O'Connor (<a href="http://www.apple.com/">Apple Inc</a>) <eoconnor @apple.com>
<dd>Dirk Schulze (<a href="http://www.adobe.com/">Adobe Systems, Inc</a>) <dschulze @adobe.com>
</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>
<p class="note">
This specification merges the former CSS 2D Transforms and CSS 3D Transforms specifications and
will also merge CSS Transforms and SVG Transforms. The merge is in progress and the specification
is not yet ready for review.
</p>
<!--status-->
<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 which each
element is positioned. Positions and sizes in this coordinate space can
be thought of as being expressed in pixels, starting in the upper left
corner of the parent with positive values proceeding to the right and
down.
</p>
<p>
This coordinate space can be modified with the <code
class="property">'transform'</code> 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 <code class="property"> 'transform-origin'</code> property
provides a convenient way to control the origin about which transforms on
an element are applied.
</li>
<li>
The <code class="property">'perspective'</code> property allows the author
to make child elements with three-dimensional transforms appear as if they live in a common
three-dimensional space.
The <code class="property">'perspective-origin'</code> property provides control
over the origin at which perspective is applied, effectively changing the location of
the "vanishing point".
</li>
<li>
The <code class="property">'transform-style'</code> 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 <code class="property">'backface-visibility'</code> 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 <code class="property">'transform'</code> 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>
<div class="issue">
There are two roles for transformations in layout: (1) transformations
that adjust the position of the affected content without changing the
normal layout of that content (much like relative positioning) and (2)
transformation of the content prior to layout that affects the layout
of that content. See <a
href="http://lists.w3.org/Archives/Public/www-style/2007Oct/0209">http://lists.w3.org/Archives/Public/www-style/2007Oct/0209</a>
for examples of both cases. The "transform" property (as defined in
this document) is equally useful for both roles. This document is
focused on satisfying the first role. There is, however, an
architectural question that arises because there needs to be a way to
distinguish which role an author of a stylesheet wants. The key
question is which is the default behavior/role for the "transform"
property and how is the other behavior/role indicated by a stylesheet
author. If you have an opinion on this topic, please send feedback.
</div>
<div class="issue">
What do fixed backgrounds do in transforms? They should probably ignore
the transform completely, since - even transformed - the object should
be acting as "porthole" through which the fixed background can be viewed
in its original form.
</div>
<!-- ======================================================================================================= -->
<h2 id="module-interactions">Module Interactions</h2>
<p>Write me</p>
<h2 id="css-values">CSS Values</h2>
<p>Write me</p>
<h2 id="definitions">Definitions</h2>
<p> When used in this specification, terms have the meanings assigned in
this section.
</p>
<dl>
<dt id="TermTransformableElement"><dfn>transformable element</dfn></dt>
<dd>
<p>
A transformable element in the HTML namespace which is either be a block-level or atomic inline-level
element, or an element the SVG namespace (see [[SVG11]]) which has the attributes 'transform',
'patternTransform' or 'gradientTransform'.
</p>
</dd>
<dt id="TermPerspectiveMatrix"><dfn>perpsective 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="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>
<!-- Define "three-dimensional transform" ? -->
</dl>
<!-- ======================================================================================================= -->
<h2 id="transform-rendering">The Transform Rendering Model</h2>
<!-- This section is normative -->
<p>
Specifying a value other than 'none' for the <code class="property">'transform'</code>
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 <code class="property">'transform'</code>
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 <code class="property">transform</code> and <code class="property">transform-origin</code> properties
as follows:
<ol>
<li>Start with the identity matrix.</li>
<li>Translate by the computed X, Y and Z values of <code class="property">transform-origin</code></li>
<li>Multiply by each of the transform functions in <code class="property">transform</code> property in turn</li>
<li>Translate by the negated computed X, Y and Z values of <code class="property">transform-origin</code></li>
</ol>
</p>
<p>
Transforms apply to <a href="#TermTransformableElement">transformable elements</a>.
</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="transform1.png" alt="The 100px translation in X and Y">
</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° 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="compound_transform.png" alt="The transform specified above">
</div>
<p>Note that an identical rendering can be obtained by nesting elements with the equivalent transforms:
<pre>
<div style="transform: translate(80px, 80px)">
<div style="transform: scale(1.5, 1.5)">
<div style="transform: rotate(45deg)"></div>
</div>
</div>
</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 <code class="property">'overflow'</code>
property is <code class="css">'scroll'</code> or <code class="css">'auto'</code>,
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 affect 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>
<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>
<style>
div { height: 150px; width: 150px; }
.container { border: 1px solid black; }
.transformed { transform: rotateY(50deg); }
</style>
<div class="container">
<div class="transformed"></div>
</div>
</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° 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 futher away to appear smaller.
</p>
<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 <code class="css">perspective(<length>)</code> 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>
<style>
div { height: 150px; width: 150px; }
.container { perspective: 500px; border: 1px solid black; }
.transformed { transform: rotateY(50deg); }
</style>
<div class="container">
<div class="transformed"></div>
</div>
</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 futher 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>
<style>
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; }
</style>
<div class="container">
<div class="transformed">
<div class="child"></div>
</div>
</div>
</pre>
<p>This exmaple shows how nested 3D transforms are rendered in the absence of <code>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 transformable element 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
<class style="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>
The final value of the transform used to render an element in a <span class="term">3D rendering context</span>
is computed by accumulating a matrix 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 contining 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>
<style>
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); background-color: lime; }
</style>
</pre>
<p>This example is identical to the previous example, with the addition of <code>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>
<div class="issue">
<p class="desc">Should intersection behavior be normative?</p>
</div>
<p>
Elements in the same <span class="term">3D rendering context</span> may intersect with eachother. User agents should
subdivide the planes of intersecting elements as described by
<a href="http://en.wikipedia.org/wiki/Newell's_algorithm">Newell's algorithm</a> to render intersection.
</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>
<style>
.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;
}
</style>
<div class="container">
<div></div>
<div></div>
</div>
</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 painted 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 (either defined in
this specification or by reference to the SVG specification), 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 | <transform-function> [ <transform-function> ]*
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
none
</td>
</tr>
<tr>
<td>
<em>Applies 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 border box
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
See below.
</td>
</tr>
</tbody>
</table>
<div class="issue">
<p class="desc">We need to resolve whether the computed value is the same as the specified value, or matrix().</p>
</div>
<p>The computed value of the transform property is a matrix() or matrix3d() value that describes the matrix that results from concatenating the individual transform functions. If the resulting matrix can be represented as a two-dimensional matrix with no loss of information, then a matrix() value is returned, otherwise a matrix3d() value. For elements with no transform applied, the computed value is 'none'.</p>
<p>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>
<!-- ======================================================================================================= -->
<h3 id="svg-transform">The SVG transform attribute</h3>
<p>The <a href="http://www.w3.org/TR/2011/REC-SVG11-20110816/">SVG 1.1 specification</a> did not
specify the 'transform' attribute as a <a href="http://www.w3.org/TR/2011/REC-SVG11-20110816/styling.html#UsingPresentationAttributes">presentation attribute</a>.
In order to improve the integration of
SVG and HTML, this specification makes the SVG 'transform' attribute a
'presentation attribute' and makes the 'transform' property one that applies to SVG elements.</p>
<h4 id="transform-attribute-specificity">SVG transform attribute specificity</h4>
<p>Since the SVG attribute becomes a presentation attribute, its participation to the CSS
cascade is determined by the specificity of presentation attributes, as
<a href="http://www.w3.org/TR/2011/REC-SVG11-20110816/styling.html#UsingPresentationAttributes">explained</a>
in the SVG specification.</p>
<h4 id="transform-attribute-dom">SVG transform attribute DOM</h4>
<p>The SVG specification <a href="http://www.w3.org/TR/2011/REC-SVG11-20110816/coords.html#InterfaceSVGAnimatedTransformList">defines</a> a DOM interface to access the animated and base value of
the SVG transform attribute. To ensure backwards compatibility, this API should still be
supported by user agents. The <code>baseVal</code> should be the value of the 'transform' attribute,
as set on the element, and the <code>animVal</code> should be the property's computed value which account
for CSS animation, if any is underway.</p>
<div class="issue">
<ul>
<li>Should we also make gradientTransform and patternTransform presentation attributes?
Proposal: they
are the 'presentation attributes' for <gradient> and >pattern< respectively,
for the 'transform' property (i.e., there is no 'gradientTransform' property. Instead, the
'gradientTransform' is a presentation attribute that provides a value for the
'transform' property that applies to the <gradient> element.)</li>
<li>Is this proposal working for SMIL animation of the transform property?</li>
</ul>
</div>
<!-- ======================================================================================================= -->
<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>
[ top | bottom ] |<br>
[ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? |<br>
[ center | [ left | right ] [ <percentage> | <length> ]? ] && [ center | [ top | bottom ] [ <percentage> | <length> ]? ]<br>
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
0 0 for SVG elements, 50% 50% for all other elements
</td>
</tr>
<tr>
<td>
<em>Applies 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 border box
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
For <length> the absolute value, otherwise a percentage
</td>
</tr>
</tbody>
</table>
<p>
The values of the <code class="property">'transform'</code> and
<code class="property">'transform-origin'</code> 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 two values are given and at least one value is not a keyword,
then the first value represents the horizontal position (or offset) and
the second represents the vertical position (or
offset). <var><percentage></var> and <var><length></var>
values here represent an offset of the transform origin from the top left corner
of the element's border box.
</p>
<p>If three or four values are given, then
each <var><percentage></var> or<var><length></var>
represents an offset and must be preceded by a keyword,
which specifies from which edge the offset is given. For example,
''transform-origin: bottom 10px right 20px'' represents a
''10px'' vertical offset up from the bottom edge and a
''20px'' horizontal offset leftward from the right edge. If
three values are given, the missing offset is assumed to be zero.
</p>
<p>Positive values represent an offset <em>inward</em> from the edge of
the border box. Negative values represent an offset
<em>outward</em> from the edge of the border box.
</p>
<h3 id="svg-transform-origin">The 'transform-origin' property for SVG elements</h3>
<div class="issue">
<p class="desc">Should we use 'auto', or explicitly say that transform-origin is 0 0 for SVG elements, 50% 50% for all other elements (<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=15504">bug 15504</a>)?</p>
</div>
<p>To keep the 'transform' property compatible with existing SVG content that assumed a top/left
coordinate system origin, the user agent stylesheet must contain the following:</p>
<pre class="css">
svg | * {
transform-origin: top left;
}
</pre>
<div class="issue">
<p class="desc">Need to add 3D transform-origin variant in a way that is not ambiguous
with the background-origin syntax (<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=15432">bug 15432</a>).</p>
</div>
<!-- ======================================================================================================= -->
<h2 id="transform-style-property">
The <code class="property">'transform-style'</code> Property
</h2>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="transform-style">transform-style</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
flat | preserve-3d
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
flat
</td>
</tr>
<tr>
<td>
<em>Applies 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>
N/A
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
Same as specified value.
</td>
</tr>
</tbody>
</table>
<p>
A value of <code class="css">preserve-3d</code> for <code class="property">transform-style</code>
establishes a stacking context.
</p>
<p>
The following CSS property values require the user agent to create a flattened representation of
the descendant elements before they can be applied, and therefore override the behavior of
<code class="property">transform-style</code>: <code class="css">preserve-3d</code>:
<ul>
<li><code class="property">overflow</code>: any value other than 'visible'.</li>
<li><code class="property">opacity</code>: any value other than 1.</li>
<li><code class="property">filter</code>: any value other than 'none'.</li>
<!-- Others? -->
</ul>
</p>
<div class="issue">
<p class="desc">Should this affect the computed value of transform-style?</p>
</div>
<p>
The values of the <code class="property">'transform'</code> and
<code class="property">'transform-origin'</code> properties are used to compute the
<a href="#TermTransformationMatrix"><i>transformation matrix</i></a>, as described above.
</p>
<!-- ======================================================================================================= -->
<h2 id="perspective-property">
The <code class="property">'perspective'</code> Property
</h2>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="perspective">perspective</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
none | <length>
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
none
</td>
</tr>
<tr>
<td>
<em>Applies 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>
N/A
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
Same as specified value.
</td>
</tr>
</tbody>
</table>
<p>
If the value is <code class="css">'none'</code>, less than or equal to 0 no
perspective transform is applied.
</p>
<p>
The use of this property with any value other than 'none' establishes a
stacking context. It also establishes a containing block (somewhat
similar to position:relative), just like the 'transform' property does.
</p>
<p>
The values of the <code class="property">perspective</code> and <code class="property">perspective-origin</code>
properties are used to compute the <a href="#TermPerspectiveMatrix"><i>perspective matrix</i></a>, as described above.
</p>
<!-- ======================================================================================================= -->