forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
2968 lines (2329 loc) · 123 KB
/
Overview.html
File metadata and controls
2968 lines (2329 loc) · 123 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">
<html lang=en>
<head profile="http://www.w3.org/2006/03/hcard"><meta
content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 3</title>
<link href="../default.css" rel=stylesheet type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 16 February
2012</h2>
<dl>
<dt>This Version:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dd><a href="http://www.w3.org/TR/2012/ED-css3-images-20120216/">http://www.w3.org/TR/2012/WD-css3-images-20120216/</a>-->
<dt>Latest Version:
<dd><a
href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a>
<dt>Editor's Draft:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous Version:
<dd><a
href="http://www.w3.org/TR/2012/WD-css3-images-20120112/">http://www.w3.org/TR/2012/WD-css3-images-20120112/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20111206/">http://www.w3.org/TR/2011/WD-css3-images-20111206/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110908/">http://www.w3.org/TR/2011/WD-css3-images-20110908/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110712/">http://www.w3.org/TR/2011/WD-css3-images-20110712/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110217/">http://www.w3.org/TR/2011/WD-css3-images-20110217/</a>
<dd><a
href="http://www.w3.org/TR/2009/WD-css3-images-20090723/">http://www.w3.org/TR/2009/WD-css3-images-20090723/</a>
<dt>Issues List:
<dd><a
href="http://www.w3.org/Style/CSS/Tracker/products/27">http://www.w3.org/Style/CSS/Tracker/products/27</a>
<dt>Discussion:
<dd><a
href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a>
with subject line “<kbd>[css3-images] <var>… message topic
…</var></kbd>”
<dt>Editors:
<dd class=vcard> <a class="url fn"
href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a> (<span
class=org>Mozilla</span>)
<dd class=vcard> <a class="url fn"
href="http://www.xanthir.com/contact/">Tab Atkins Jr.</a> (<span
class=org>Google</span>)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2012 <a
href="http://www.w3.org/"><acronym
title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym
title="Massachusetts Institute of Technology">MIT</acronym></a>, <a
href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>CSS is a language for describing the rendering of structured documents
(such as HTML and XML) on screen, on paper, in speech, etc. This module
contains the features of CSS level 3 relating to the <image> type
and replaced elements. It includes and extends the functionality of CSS
level 2 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, which builds on CSS
level 1 <a href="#CSS1" rel=biblioentry>[CSS1]<!--{{CSS1}}--></a>.
The main extensions compared to level 2 are the generalization of the
<url> type to the <image> type, several additions to the ‘<a
href="#ltimage"><code class=css><image></code></a>’ type, a
generic sizing algorithm for images and other replaced content in CSS, and
several properties controlling the interaction of replaced elements and
CSS's layout models.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-images%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-images” in the subject, preferably like this:
“[<!---->css3-images<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p>​​​​​This specification is a <strong>Last
Call Working Draft</strong>. All persons are encouraged to review this
document and <strong>send comments to the <a
href="http://lists.w3.org/Archives/Public/www-style/">www-style</a>
mailing list</strong> as described above. The <strong>deadline for
comments</strong> is <strong>7 February 2012</strong>.
<p>The following features are at risk: …
<ol>
<li>The <a href="#image-notation">image()</a> and <a
href="#element-reference">element()</a> notations
<li>The ‘<a href="#object-fit0"><code
class=property>object-fit</code></a>’, ‘<a
href="#object-position0"><code
class=property>object-position</code></a>’, ‘<a
href="#image-orientation0"><code
class=property>image-orientation</code></a>’, and ‘<a
href="#image-resolution0"><code
class=property>image-resolution</code></a>’ properties
</ol>
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction</a>
<ul class=toc>
<li><a href="#placement"><span class=secno>1.1. </span> Module
Interactions</a>
<li><a href="#values"><span class=secno>1.2. </span> Values</a>
</ul>
<li><a href="#resolution-units"><span class=secno>2. </span> Resolution
Units: the <resolution> type</a>
<li><a href="#image"><span class=secno>3. </span> Image Values: the
<image> type</a>
<ul class=toc>
<li><a href="#url"><span class=secno>3.1. </span> Image References and
Image Slices: the ‘<code class=css>url()</code>’
notation</a>
<li><a href="#image-notation"><span class=secno>3.2. </span> Image
Fallbacks and Annotations: the ‘<code
class=css>image()</code>’ notation</a>
<li><a href="#element-reference"><span class=secno>3.3. </span> Using
Elements as Images: the ‘<code class=css>element()</code>’
notation</a>
<ul class=toc>
<li class=no-num><a href="#paint-sources"> Paint Sources</a>
<li class=no-num><a href="#element-cycles"> Cycle Detection</a>
</ul>
</ul>
<li><a href="#gradients"><span class=secno>4. </span> Gradients</a>
<ul class=toc>
<li><a href="#linear-gradients"><span class=secno>4.1. </span> Linear
Gradients: the ‘<code class=css>linear-gradient()</code>’
notation</a>
<li><a href="#radial-gradients"><span class=secno>4.2. </span> Radial
Gradients: the ‘<code class=css>radial-gradient()</code>’
notation</a>
<li><a href="#repeating-gradients"><span class=secno>4.3. </span>
Repeating Gradients: the ‘<code
class=css>repeating-linear-gradient()</code>’ and ‘<code
class=css>repeating-radial-gradient()</code>’ notations</a>
<li><a href="#color-stop-syntax"><span class=secno>4.4. </span> Gradient
Color-Stops</a>
</ul>
<li><a href="#sizing"><span class=secno>5. </span> Sizing Images and
Objects in CSS</a>
<ul class=toc>
<li><a href="#sizing-terms"><span class=secno>5.1. </span> Object-Sizing
Terminology</a>
<li><a href="#object-negotiation"><span class=secno>5.2. </span>
CSS⇋Object Negotiation</a>
<li><a href="#default-sizing"><span class=secno>5.3. </span> Default
Concrete Object Size Resolution</a>
<li><a href="#object-fit"><span class=secno>5.4. </span> Sizing Objects:
the ‘<code class=property>object-fit</code>’ property</a>
<li><a href="#object-position"><span class=secno>5.5. </span>
Positioning Objects: the ‘<code
class=property>object-position</code>’ property</a>
</ul>
<li><a href="#image-processing"><span class=secno>6. </span> Image
Processing</a>
<ul class=toc>
<li><a href="#image-resolution"><span class=secno>6.1. </span>
Overriding Image Resolutions: the ‘<code
class=property>image-resolution</code>’ property</a>
<li><a href="#image-orientation"><span class=secno>6.2. </span>
Orienting an Image on the Page: the ‘<code
class=property>image-orientation</code>’ property</a>
</ul>
<li><a href="#conformance"><span class=secno>7. </span> Conformance</a>
<ul class=toc>
<li><a href="#conventions"><span class=secno>7.1. </span> Document
Conventions</a>
<li><a href="#conformance-classes"><span class=secno>7.2. </span>
Conformance Classes</a>
<li><a href="#partial"><span class=secno>7.3. </span> Partial
Implementations</a>
<li><a href="#experimental"><span class=secno>7.4. </span> Experimental
Implementations</a>
<li><a href="#testing"><span class=secno>7.5. </span>Non-Experimental
Implementations</a>
<li><a href="#cr-exit-criteria"><span class=secno>7.6. </span> CR Exit
Criteria</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span> Introduction</h2>
<p><em>This section is not normative.</em>
<p>In CSS Levels 1 and 2, image values, such as those used in the
‘<code class=property>background-image</code>’ property, could
only be given by a single URL value. This module introduces additional
ways of representing 2D images, for example as <a href="#image-notation">a
list of URIs denoting fallbacks</a>, as <a href="#element-reference">a
reference to an element</a>, or as <a href="#gradients">a gradient</a>.
<p>This module also defines several properties for <a
href="#image-processing">manipulating raster images</a> and for <a
href="#object-fit">sizing</a> or <a
href="#object-position">positioning</a> replaced elements such as images
within the box determined by the CSS layout algorithms. It also defines in
a generic way CSS's <a href="#sizing">sizing algorithm</a> for images and
other replaced elements.
<h3 id=placement><span class=secno>1.1. </span> Module Interactions</h3>
<p>This module defines and extends the ‘<a href="#ltimage"><code
class=css><image></code></a>’ value type defined in <a
href="#CSS3VAL" rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>.
Furthermore it replaces the ‘<code class=css><url></code>’
type in the ‘<code class=property>background-image</code>’ and
‘<code class=property>list-style-image</code>’ definitions in
CSS1 and CSS2 and adds ‘<a href="#ltimage"><code
class=css><image></code></a>’ as an alternative to ‘<code
class=css><url></code>’ in the ‘<code
class=property>content</code>’ property's value. It is presumed that
CSS specifications beyond CSS2.1 will use the ‘<a
href="#ltimage"><code class=css><image></code></a>’ notation in
place of ‘<code class=css><url></code>’ where 2D images are
expected. (See e.g. <a href="#CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>.)
<h3 id=values><span class=secno>1.2. </span> Values</h3>
<p>This specification follows the <a
href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 <a
href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. Other CSS
modules may expand the definitions of these value types: for example <a
href="#CSS3COLOR" rel=biblioentry>[CSS3COLOR]<!--{{CSS3COLOR}}--></a>,
when combined with this module, expands the definition of the <color>
value type as used in this specification.
<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=resolution-units><span class=secno>2. </span> Resolution Units: the
<resolution> type</h2>
<p>This specification defines the following units as part of the <dfn
id=ltresolution><resolution></dfn> value type:
<dl>
<dt><dfn id=dpi>‘<code class=css>dpi</code>’</dfn>
<dd>dots per inch
<dt><dfn id=dpcm>‘<code class=css>dpcm</code>’</dfn>
<dd>dots per centimeter
<dt><dfn id=dppx>‘<code class=css>dppx</code>’</dfn>
<dd>dots per ‘<code class=css>px</code>’ unit
</dl>
<p>The <resolution> unit represents the size of a single "dot" in a
graphical representation by indicating how many of these dots fit in a CSS
‘<code class=property>in</code>’, ‘<code
class=property>cm</code>’, or ‘<code
class=property>px</code>’. For uses, see e.g. the ‘<code
class=css>resolution</code>’ media query in <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> or the ‘<a
href="#image-resolution0"><code
class=property>image-resolution</code></a>’ property defined below.
<p class=note>Note that due to the 1:96 fixed ratio of CSS ‘<code
class=css>in</code>’ to CSS ‘<code class=css>px</code>’,
‘<code class=css>1dppx</code>’ is equivalent to ‘<code
class=css>96dpi</code>’. This corresponds to the default resolution
of images displayed in CSS: see ‘<a href="#image-resolution0"><code
class=property>image-resolution</code></a>’.
<div class=example>
<p>The following @media rule uses Media Queries <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a> to assign some special
style rules to devices that use two or more device pixels per CSS
‘<code class=css>px</code>’ unit:
<pre>@media (min-resolution: 2dppx) { ... }</pre>
</div>
<!-- ====================================================================== -->
<h2 id=image><span class=secno>3. </span> Image Values: the <image> type</h2>
<p>The <image> value type denotes a 2D image. It represents either a <a
href="#url">url reference</a>, <a href="#image-notation">image
notation</a>, <a href="#element-reference">element reference</a>, or <a
href="#gradients">gradient notation</a>. Syntactically it is defined as
<pre class=prod><dfn id=ltimage><image></dfn> = <i><url></i> | <a
href="#ltimage-list"><i><image-list></i></a> | <a
href="#ltelement-reference"><i><element-reference></i></a> | <a
href="#ltgradient"><i><gradient></i></a></pre>
<p>Image values can be used in many CSS properties, including the
‘<code class=property>background-image</code>’, ‘<code
class=property>list-style-image</code>’, ‘<code
class=property>cursor</code>’ properties <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<!-- ====================================================================== -->
<h3 id=url><span class=secno>3.1. </span> Image References and Image
Slices: the ‘<code class=css>url()</code>’ notation</h3>
<p>The simplest way to indicate an image is to reference an image file by
URL. This is done with the <a
href="http://www.w3.org/TR/CSS21/syndata.html#uri">‘<code
class=css>url()</code>’ notation</a>, defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<div class=example>
<p>In the example below, a background image is specified with ‘<code
class=css>url()</code>’ syntax:</p>
<pre>background-image: url(wavy.png);</pre>
</div>
<p>A portion of an image may be referenced (clipped out and used as a
standalone image) by use of <a
href="http://www.w3.org/TR/media-frags/#naming-space">media fragment
identifiers</a>. <a href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<div class=example>
<p>For example, given the following image* and CSS:</p>
<a href=sprites.svg> <img alt="[9 circles, with 0 to 8 eighths filled in]"
height=20 src=sprites.svg width=180> </a>
<pre>background-image: url('sprites.svg#xywh=40,0,20,20')</pre>
<p>...the background of the element will be the portion of the image that
starts at (40px,0px) and is 20px wide and tall, which is just the circle
with a quarter filled in.</p>
<p><small>* SVG-in-<img> support required. Click the picture to view
the SVG directly.</small></p>
</div>
<p class=note>Note that a legacy UA that doesn't understand the media
fragments notation will ignore the fragment and simply display the
entirety of an image specified with ‘<code
class=css>url</code>’. However, since URLs with media fragment
identifiers can also be used in the ‘<code
class=css>image()</code>’ notation defined below, authors can take
advantage of CSS's forward-compatible parsing rules to provide a fallback
when using an image fragment URL:
<div class=example>
<p>In the example below, the ‘<code class=css>image()</code>’
notation is used together with the media fragment syntax, so that UAs
that don't support media fragments fail to parse the second declaration
and use the first.</p>
<pre>
<!-- -->background-image: url('swirl.png'); /* old UAs */
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
</div>
<!-- ====================================================================== -->
<h3 id=image-notation><span class=secno>3.2. </span> Image Fallbacks and
Annotations: the ‘<code class=css>image()</code>’ notation</h3>
<p>The ‘<code class=css>image()</code>’ function allows an
author to specify an image with fallback images to be used if the original
image can't be decoded or is a type that the browser doesn't recognize.
Additionally, the author can specify a color as an ultimate fallback to be
used when none of the images can be.
<p>So that authors can take advantage of CSS's forwards-compatible parsing
rules to provide a fallback for image slices, implementations that support
the ‘<code class=css>image()</code>’ notation <em>must</em>
support the <code>xywh=#,#,#,#</code> form of media fragment identifiers
for images. <a href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<p>The ‘<code class=css>image()</code>’ notation is defined as:
<pre class=prod><dfn
id=ltimage-list><image-list></dfn> = image( [ <image-decl> , ]* [ <image-decl> | <color> ] )
<dfn
id=ltimage-decl><image-decl></dfn> = <string> [ ltr | rtl ]?</pre>
<p>Each <code><string></code> represents a <a
href="h
EE73
ttp://dev.w3.org/csswg/css3-values/#urls">URL</a>. The computed
value of an <a href="#ltimage-list"><i><image-list></i></a> is the same
as specified, except with all relative URLs converted into absolute URLs.
<p>Multiple arguments can be given separated by commas, in which case the
function represents the first <string> representing an image that the
browser can successfully load and display. The final argument can specify
a <color> to serve as an ultimate fallback; this can be used, e.g. for
‘<code class=property>background-image</code>’, to ensure
adequate contrast if none of the preceding <image-decl>s can be used.
If the final argument is a <color>, it represents a solid-color image
of the given color with no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>.
<div class=example>
<p>The rule below would tell the UA to load ‘<code
class=css>wavy.svg</code>’ if it can; failing that to load
‘<code class=css>wavy.png</code>’; failing that to display
‘<code class=css>wavy.gif</code>’. For example, the browser
might not understand how to render SVG images, and the PNG may be
temporarily 404 (returning an HTML 404 page, which the browser can't
decode as an image) due to a server move, so the GIF is used until one of
the previous problems corrects itself.</p>
<pre>background-image: image("wavy.svg", 'wavy.png' , "wavy.gif");</pre>
</div>
<div class=example>
<p>The fallback color can be used to ensure that text is still readable
even when the image fails to load. For example, the following code works
fine if the image is rectangular and has no transparency:</p>
<pre>
body { color: black; background: white; }
p.special { color: white; background: url("dark.png") black; }</pre>
<p>When the image doesn't load, the background color is still there to
ensure that the white text is readable. However, if the image has some
transparency, the black will be visible behind it, which is probably not
desired. The ‘<code class=css>image()</code>’ function
addresses this:</p>
<pre>
body { color: black; background: white; }
p.special { color: white; background: image("dark.png", black); }</pre>
<p>Now, the black won't show at all if the image loads, but if for
whatever reason the image fails, it'll pop in and prevent the white text
from being set against a white background.</p>
</div>
<div class=example>
<p>At times, one may need a solid-color image for a property or function
that does not accept the <color> type directly. The ‘<code
class=css>image()</code>’ function can be used for this: by
specifying <em>only</em> a color without any URLs, the function
immediately falls back to representing a solid-color image of the chosen
color.
<pre>background-image: image(rgba(0,0,255,.5)), url("bg-image.png");</pre>
<p>In the above, the background is the image "bg-image.png", overlaid with
partially-transparent blue.
</div>
<p>Along with each URL, the author may specify a directionality, similar to
adding a <code>dir</code> attribute to an element in HTML. The image
represented by the function takes on the directionality of the used URL.
If a directional image is used on or in an element with opposite <a
href="http://www.w3.org/TR/CSS21/visuren.html#propdef-direction">direction</a>,
the image must be flipped in the inline direction (as if it was
transformed by, e.g., <code>scaleX(-1)</code>, if the inline direction is
the X axis).
<div class=example>
<p>A list may use an arrow for a bullet that points into the content. If
the list can contain both LTR and RTL text, though, the bullet may be on
the left or the right, and an image designed to point into the text on
one side will point out of the text on the other side. This can be fixed
with code like:</p>
<pre>
<ul style="list-style-image: image("arrow.png" ltr);">
<li dir='ltr'>My bullet is on the left!</li>
<li dir='rtl'>MY BULLET IS ON THE RIGHT!</li>
</ul></pre>
<p>This should render something like:</p>
<pre>
⇒ My bullet is on the left!
!THGIR EHT NO SI TELLUB YM ⇐</pre>
<p>In LTR list items, the image will be used as-is. In the RTL list items,
however, it will be flipped in the inline direction, so it still points
into the content.</p>
</div>
<!-- ====================================================================== -->
<h3 id=element-reference><span class=secno>3.3. </span> Using Elements as
Images: the ‘<code class=css>element()</code>’ notation</h3>
<p>The ‘<code class=css>element()</code>’ function allows an
author to use an element in the document as an image. As the referenced
element changes appearance, the image changes as well. This can be used,
for example, to create live previews of the next/previous slide in a
slideshow, or to reference a canvas element for a fancy generated gradient
or even an animated background. The syntax for ‘<code
class=css>element()</code>’ is:
<pre class=prod><dfn
id=ltelement-reference><element-reference></dfn> = element( <id-selector> )</pre>
<p>where <id-selector> is an ID selector <a href="#SELECT"
rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>.
<p>If the argument to the ‘<code class=css>element()</code>’
function is an ID selector, the function references the element matched by
the selector. If multiple elements are matched by the selector, the
function references the first such element.
<p>HTML defines an additional way for an element to match this ID selector,
via the <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-csselementmap"><code>CSSElementMap</code></a>.
If an element matching the ID selector is not found in the document, the
ID is then looked up in the <code>CSSElementMap</code>. Other host
languages may define additional ways for elements to match the argument in
‘<code class=css>element()</code>’.
<div class=example>
<p>The ‘<code class=css>element()</code>’ function can be put
to many uses. For example, it can be used to show a preview of the
previous or next slide in a slideshow:</p>
<pre>
<!DOCTYPE html>
<script>
function navigateSlides() {
var currentSlide = ...;
var prevSlide = currentSlide.previousElementSibling;
var nextSlide = currentSlide.nextElementSibling;
document.CSSElementMap['prev-slide'] = prevSlide;
document.CSSElementMap['next-slide'] = nextSlide;
}
</script>
<style>
#prev-preview, #next-preview {
position: fixed;
...
}
#prev-preview { background: element(#prev-slide); }
#next-preview { background: element(#next-slide); }
</style>
<div id='prev-preview'></div>
<div id='next-preview'></div>
<section class='slide'>...</section>
<section class='slide current-slide'>...</section>
...</pre>
<p>In this example, the <code>navigateSlides</code> function updates
HTML's <code>CSSElementMap</code> to always point to the next and
previous slides, which are then displayed in small floating boxes
alongside the slides. Since you can't interact with the slides through
the ‘<code class=css>element()</code>’ function (it's just an
image), you could even use <code>click</code> handlers on the preview
boxes to help navigate through the page.
<p class=note>Note: A future version of this specification may allow more
than just ID selectors to be passed to ‘<code
class=css>element()</code>’, allowing an example like this to be
done with even less javascript - something like ‘<code
class=css>background: element(.current-slide + .slide);</code>’.</p>
</div>
<p>The image represented by the ‘<code
class=css>element()</code>’ function can vary based on a number of
factors. The function must represent the image described by the first set
of conditions, following, that are true:
<dl>
<dt>The function doesn't reference an element
<dd>The function represents a solid-color transparent-black image with no
intrinsic dimensions.
<dt>The function references an element that is not rendered, but which <a
href="#paint-source"><i title=paint-source>provides a paint
source</i></a>
<dd>
<p>The function represents an image with the dimensions and appearance of
the <a href="#paint-source"><i title=paint-source>paint source</i></a>.
The host language defines the dimensions and appearance of paint
sources.
<div class=example>
<p>For example, the ‘<code class=css>element()</code>’
function can reference an SVG <pattern> element in an HTML document:</p>
<pre>
<!DOCTYPE html>
<svg>
<defs>
<pattern id='pattern1'>
<path d='...'>
</pattern>
</defs>
</svg>
<p style="background: element(#pattern1)">
I'm using the pattern as a background!
If the pattern is changed or animated,
my background will be updated too!
</p></pre>
<p>HTML also defines that a handful of elements, such as <canvas>,
<img>, and <video>, provide a paint source. This means that CSS
can, for example, reference a canvas that's being drawn into, but not
included in the page:</p>
<pre>
<!DOCTYPE html>
<script>
var canvas = document.createElement('canvas');
canvas.width = 20; canvas.height = 20;
document.CSSElementMap.foo = canvas;
drawAnimation(canvas);
</script>
<ul style="list-style-image: element(#foo);">
<li>I'm using the canvas as a bullet!</li>
<li>So am I!</li>
<li>As the canvas is changed over time with Javascript,
we'll all update our bullet image with it!</li>
</ul></pre>
</div>
<dt>The function references an element that is not rendered
<dt>The function references an element that is a descendant of a replaced
element
<dd>
<p>The function represents a solid-color transparent-black image with no
intrinsic dimensions.</p>
<div class=example>
<p>For example, all of the following ‘<code
class=css>element()</code>’ uses will result in a transparent
background:</p>
<pre>
<!DOCTYPE html>
<script>
var p = document.createElement('p');
p.textContent = "one";
document.CSSElementMap.one = p;
</script>
<p id='two' style="display:none;">two</p>
<iframe src="http://example.com">
<p id='three'>I'm fallback content!</p>
</iframe>
<ul>
<li style="background: element(#one);">
A P element doesn't provide a paint source,
and it's not rendered unless it's in a document.
</li>
<li style="background: element(#two);">
Similarly, a display:none element isn't rendered, and
P still doesn't provide a paint source.
</li>
<li style="background: element(#three);">
The descendants of a replaced element like an IFRAME
can't be used in element() either.
</li>
</ul></pre>
</div>
<dt>Otherwise
<dd>
<p>The function represents an image with width and height equal to the
border box of the referenced element. The image must be constructed by
rendering the referenced element and its descendants at the same size
that the element would be in its document, over an infinite
transparent-black canvas, positioned so that the edges of the referenced
element's border box is flush with the edges of the image. <span
class=note>Note: Because images clip anything outside their bounds by
default, this means that decorations that extend outside the border box,
like box-shadows or some border-images, may be clipped.</span></p>
<p>If the referenced element has a transform applied to it or an
ancestor, the transform must be ignored when rendering the element as an
image. If the referenced element is broken across pages, the element
must be displayed as if the page content areas were joined flush in the
pagination direction (elements broken across lines or columns just
render with their border box, as normal, which may have unintended
visual effects).</p>
<div class=example>
<p>As a somewhat silly example, a <p> element can be reused as a
background elsewhere in the document:</p>
<pre>
<style>
#src { color: white; background: lime; width: 300px; height: 40px; }
#dst { color: black; background: element(#src); padding: 20px; margin: 20px 0; }
</style>
<p id='src'>I'm an ordinary element!</p>
<p id='dst'>I'm using the previous element as my background!</p></pre>
<img alt="" src=element-function.png></div>
</dl>
<p>Implementations may either re-use existing bitmap data generated for the
referenced element or regenerate the display of the element to maximize
quality at the image's size (for example, if the implementation detects
that the referenced element is an SVG fragment); in the latter case, the
layout of the referenced element in the image must not be changed by the
regeneration process. That is, the image must look identical to the
referenced element, modulo rasterization quality.
<h4 class=no-num id=paint-sources> Paint Sources</h4>
<p>Host languages may define that some elements provide a <dfn
id=paint-source title=paint-source>paint source</dfn>. Paint sources have
an intrinsic width, height, and appearance, separate from the process of
rendering, and so may be used as images even when they're not being
rendered.
<p>In HTML, the <img>, <video>, and <canvas> elements provide
paint sources (defined in each element's section in <a
href="http://www.whatwg.org/specs/web-apps/current-work/multipage/">HTML5</a>).
<p>In SVG, any element that provides a <a
href="http://www.w3.org/TR/SVG/pservers.html">paint server</a> provides a
paint source. In SVG1.1, the <linearGradient>, <radialGradient>, and
<pattern> elements provide paint sources. They are drawn as described
in the spec, with the coordinate systems defined as follows:
<dl>
<dt>objectBoundingBox
<dd>The coordinate system has its origin at the top left corner of the
painting area. The width and height of the painting area are the width
and height of a single unit in the coordinate system.
<dt>userSpaceOnUse
<dd>The coordinate system has its origin at the top left corner of the
painting area. Units in the coordinate space are sized equivalently to
the CSS ‘<code class=css>px</code>’ unit.
</dl>
<!-- ====================================================================== -->
<h4 class=no-num id=element-cycles> Cycle Detection</h4>
<p>The ‘<code class=css>element()</code>’ function can produce
nonsensical circular relationships, such as an element using itself as its
own background. These relationships can be easily and reliably detected
and resolved, however, by keeping track of a dependency graph and using
common cycle-detection algorithms.
<p>The dependency graph consists of edges such that:
<ul>
<li>every element depends on its children
<li>for any element A with a property using the ‘<code
class=css>element()</code>’ function pointing to an element B, A
depends on B
<li>if a host language defines a way for elements to refer to the
rendering of other elements, the referencing element depends on the
referenced element. For example, in SVG, a <use> element depends on
the element it referenced.
</ul>
<p>If the graph contains a cycle, any ‘<code
class=css>element()</code>’ functions participating in the cycle
must represent a fully transparent image with no intrinsic dimensions.
<p class=issue>Someone else needs to review this and make sure that I'm not
missing any cycles.
<h2 id=gradients><span class=secno>4. </span> Gradients</h2>
<p>A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons,
and many other things. The gradient notations described in this section
allow an author to specify such an image in a terse syntax, so that the UA
can generate the image automatically when rendering the page. The syntax
of a <a href="#ltgradient"><i><gradient></i></a> is:
<pre class=prod><dfn id=ltgradient><gradient></dfn> = [
<a
href="#ltlinear-gradient"><i><linear-gradient></i></a> | <a
href="#ltradial-gradient"><i><radial-gradient></i></a> |
<a
href="#ltrepeating-linear-gradient"><i><repeating-linear-gradient></i></a> | <a
href="#ltrepeating-radial-gradient"><i><repeating-radial-gradient></i></a> ]</pre>
<div class=example>
<p>As with the other <a href="#ltimage"><i><image></i></a> types
defined in this specification, gradients can be used in any property that
accepts images. For example:</p>
<ul>
<li><code>background: linear-gradient(white, gray);</code>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%,
#0000af 100%, white 100%)</code>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <a
href="#concrete-object-size"><i>concrete object size</i></a>, referred to
as the <dfn id=gradient-box>gradient box</dfn>. However, the gradient
itself has no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>.
<div class=example>
<p>For example, if you use a gradient as a background, by default the
gradient will draw into a <a href="#gradient-box"><i>gradient box</i></a>
the size of the element's padding box. If ‘<code
class=property>background-size</code>’ is explicitly set to a value
such as ‘<code class=css>100px 200px</code>’, then the <a
href="#gradient-box"><i>gradient box</i></a> will be 100px wide and 200px
tall. Similarly, for a gradient used as a ‘<code
class=property>list-style-image</code>’, the box would be a 1em
square, which is the <a href="#default-object-size"><i>default object
size</i></a> for that property.</p>
</div>
<!-- ====================================================================== -->
<h3 id=linear-gradients><span class=secno>4.1. </span> Linear Gradients:
the ‘<code class=css>linear-gradient()</code>’ notation</h3>
<p>A linear gradient is created by specifying a gradient line and then
several colors placed along that line. The image is constructed by
creating an infinite canvas and painting it with lines perpendicular to
the gradient line, with the color of the painted line being the color of
the gradient line where the two intersect. This produces a smooth fade
from each color to the next, progressing in the specified direction.</p>
<!-- ====================================================================== -->
<h4 class=no-toc id=linear-gradient-syntax><span class=secno>4.1.1. </span>
linear-gradient() syntax</h4>
<pre class=prod><code>
<dfn
id=ltlinear-gradient><linear-gradient></dfn> = linear-gradient(
[ [ <angle> | to <side-or-corner> ] ,]?
<color-stop>[, <color-stop>]+
)
<dfn
id=side-or-corner><side-or-corner></dfn> = [left | right] || [top | bottom]</code></pre>
<p>The first argument to the function specifies the <dfn
id=gradient-line>gradient line</dfn>, which gives the gradient a direction
and determines how color-stops are positioned. It may be omitted; if so,
it defaults to "to bottom".
<p>The <a href="#gradient-line"><i>gradient line</i></a> may be specified
in two different ways. The first is by specifying the angle the <a
href="#gradient-line"><i>gradient line</i></a> should assume; for the
purposes of this argument, 0deg points upwards, 90deg points toward the
right, and positive angles go clockwise. The starting-point and
ending-point of the <a href="#gradient-line"><i>gradient line</i></a> are
determined by extending a line in both directions from the center of the
<a href="#gradient-box"><i>gradient box</i></a> at the angle specified. In
the direction of the angle, the ending-point is the point on the <a
href="#gradient-line"><i>gradient line</i></a> where a line drawn
perpendicular to the <a href="#gradient-line"><i>gradient line</i></a>
would intersect the corner of the <a href="#gradient-box"><i>gradient
box</i></a> in that direction. The starting-point is determined
identically, except in the opposite direction of the angle.
<p>Alternately, the direction may be specified with keywords that denote
the direction. If the argument is ‘<code class=css>to
top</code>’, ‘<code class=css>to right</code>’,
‘<code class=css>to bottom</code>’, or ‘<code
class=css>to left</code>’, the gradient must be rendered identically
to ‘<code class=css>0deg</code>’, ‘<code
class=css>90deg</code>’, ‘<code
class=css>180deg</code>’, or ‘<code
class=css>270deg</code>’, respectively. If the argument specifies a
corner to angle towards, the gradient must be rendered identically to an
angle-based gradient with an angle chosen such that the endpoint of the
gradient is in the same quadrant as the indicated corner, and a line drawn
perpendicular to the gradient line through the center of the <a
href="#gradient-box"><i>gradient box</i></a> intersects the two
neighboring corners.
<p class=note>It is expected that the next level of this module will