-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
1205 lines (1037 loc) · 36.4 KB
/
Overview.bs
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
<pre class='metadata'>
Title: CSS Shapes Module Level 1
Status: ED
Work Status: Testing
Shortname: css-shapes
Level: 1
Group: csswg
TR: https://www.w3.org/TR/css-shapes/
ED: https://drafts.csswg.org/css-shapes/
Previous Version: http://www.w3.org/TR/2014/CR-css-shapes-1-20140320/
Editor: Rossen Atanassov, Microsoft Corporation, ratan@microsoft.com, w3cid 49885
Editor: Alan Stearns, Adobe, stearns@adobe.com, w3cid 46659
Former Editor: Vincent Hardy
Abstract: CSS Shapes describe geometric shapes for use in CSS. For Level 1, CSS Shapes can be applied to floats. A circle shape on a float will cause inline content to <a>wrap</a> around the circle shape instead of the float's bounding box.
Link Defaults: css2 (property) margin
</pre>
<pre class='link-defaults'>
spec:css-masking-1; type: value
text: nonzero
text: evenodd
spec:css-shapes; type: value
text: closest-side
text: farthest-side
spec:svg2; type:property;
text:fill-rule
</pre>
<style type="text/css">
.singleImgExample {
display: block;
margin: auto;
}
</style>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
Shapes define arbitrary geometries
that can be used as CSS values.
This specification defines properties
to control the geometry
of an element's <a>float area</a>.
The 'shape-outside' property uses shape values
to define the <a>float area</a> for a float.
Note: Future levels of CSS Shapes will allow use of shapes
on elements other than floats.
Other CSS modules can make use of shapes as well,
such as CSS Masking [[CSS-MASKING]]
and CSS Exclusions [[CSS3-EXCLUSIONS]].
Note: If a user agent implements both CSS Shapes
and CSS Exclusions,
the 'shape-outside' property defines
the exclusion area for an exclusion.
Note: A future level of CSS Shapes will define a shape-inside property,
which will define a shape to <a>wrap</a> content within the element.
<h3 id="module-interactions">
Module Interactions</h3>
This module extends the float features defined in [[!CSS2]] chapter 9.
<h3 id="values">Values</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> keywords as their property value.
For readability they have not been repeated explicitly.
<h3 id=animations>Animated Values</h3>
It is expected that CSS will include ways
to animate transitions between styles.
(The section
<a href="https://www.w3.org/TR/css3-transitions/#animatable-types">"Animation of property types"</a>
of the <cite>CSS Transitions module</cite> [[CSS3-TRANSITIONS]]
is expected to define how different kinds
of values are interpolated during a transition.)
In anticipation of that,
this module includes a line "Animatable" for each property,
which specifies whether and how values
of the property can be animated.
<h3 id="terminology">
Terminology</h3>
<dfn data-lt="wrap|wrapping">Wrap</dfn>
This specification uses the term <a>wrap</a>
to refer to flowing content
around the sides of a <a>float area</a>,
defined in [[!CSS2]] chapter 9.
Content <a>wraps</a> around the right side
of a left-floated box,
and content <a>wraps</a> around the left side
of a right-floated box.
One result of this <a>wrapping</a>
is that line boxes next to a float
are shortened as necessary
to avoid intersections with the <a>float area</a>.
<dfn>Float area</dfn>
The area used
for <a>wrapping</a> content
around a float element.
The rules for float behavior
use the sides of the <a>float area</a>
to determine where content flows.
By default,
the <a>float area</a> is the float element's
<a>margin box</a>
(note this can be different than
the <a>float area</a> produced
by the ''margin-box'' value,
which includes border-radius curvature).
This specification's 'shape-outside' property
can be used to define an arbitrary,
non-rectangular <a>float area</a>.
<h2 id="relation-to-box-model-and-float-behavior">
Relation to the box model and float behavior</h2>
While the boundaries used
for <a>wrapping</a> inline flow content
outside a float
can be defined using shapes,
the actual box model does not change.
If the element has specified
margins, borders or padding
they will be computed and rendered
according to the [[!CSS3BOX]] module.
Also, float positioning and stacking are not affected
by defining a <a>float area</a> with a shape.
When a shape is used to define
a <a>float area</a>,
the shape is clipped
to the float's margin box.
In other words,
a shape can only ever reduce
a <a>float area</a>,
not increase it.
A reduced <a>float area</a> may have no effect
on some line boxes
that would normally be affected by the float.
If a shape does not enclose any area,
the shape’s edges are still used
to define the <a>float area</a>.
A <a>float area</a> defined by a shape
may reduce the normal <a>float area</a> on all sides,
but this does not allow content to <a>wrap</a>
on both sides of a float.
Left floats with a 'shape-outside' still
only allow content <a>wrapping</a> on the right side,
and right floats only allow <a>wrapping</a> on the left.
<div class="example">
In the following example
the left and right floating
<code class="html">img</code> elements
specify a triangular shape
using the 'shape-outside' property.
<pre><code>
<img class="left" src="hand.svg"/>
<img class="right" src="hand.svg"/>
<p>
Sometimes a web page's text content appears to be
funneling your attention towards a spot on the page
to drive you to follow a particular link. Sometimes
you don't notice.
</p>
<style type="text/css">
.left {
shape-outside: polygon(0 0, 100% 100%, 0 100%);
float: left;
width: 40%;
height: 12ex;
transform: scaleX(-1);
}
.right {
shape-outside: polygon(100% 0, 100% 100%, 0 100%);
float: right;
width: 40%;
height: 12ex;
}
p {
text-align: center;
}
</style>
</code>
</pre>
<img class="singleImgExample" src="images/hand-funnel.png" alt="Using the shape-outside property with floats"/>
</div>
<div class="example">
Since shapes are clipped to the float's margin box,
adding this shape to the left float above
would result in the same rendering.
<pre><code>
shape-outside: polygon(0 0, 500% 500%, 0 500%);
</code>
</pre>
</div>
<div class="example">
A shape that does not enclose any area
still has edges that contribute to the <a>float area</a>.
This inset shape is a vertical line positioned
at the midpoint of the reference box.
This midpoint edge is used as the edge
of the float area for wrapping content.
<pre><code>
shape-outside: inset(0% 50% 0% 50%);
</code></pre>
If inset values add up to more than the width,
[[css-backgrounds-3#corner-overlap]] rules are used to determine
the edges of the rectangle.
This shape results in a vertical edge
25% from the left side of the reference box.
<pre><code>
shape-outside: inset(0% 150% 50% 0%);
</code></pre>
If the shape is only a horizontal line,
then it is an empty float area and has no effect on wrapping.
Note that in this example shape-margin must be 0px
(otherwise the line would expand to enclose an area).
<pre><code>
shape-outside: inset(50% 0% 0% 50%);
shape-margin: 0px;
</code></pre>
</div>
<div class="example">
A 'shape-outside' can create open areas
on both the left and right
of a <a>float area</a>.
Content still <a>wraps</a> only on one side
of a float in this case.
In the picture,
the shape is rendered in blue,
and the content area outside the shape in mauve.
<pre><code>
shape-outside: polygon(50px 0px, 100px 100px, 0px 100px);
</code>
</pre>
<img class="singleImgExample" src="images/float-side-example.png" alt="wrapping around right side of a left-float float area"/>
</div>
<div class="example">
The following styling creates
a shape much smaller than
the float's content area,
and adds a margin-top to the float.
In the picture,
the shape is rendered in blue,
the content area outside the shape in mauve,
and the margin area of the float box in yellow.
The inline content only <a>wraps</a> around the shape,
and otherwise overlays the rest
of the float margin box.
<pre><code>
.float-left {
shape-outside: polygon(0% 50%, 50% 100%, 0 100%);
float: left;
width: 100px;
height: 100px;
margin-top: 20px;
}
</code></pre>
<img class="singleImgExample" src="images/float-margin-example.png" alt="Adding margin-top to a float with a small shape-outside"/>
The next picture shows a possible result
if two of these floats
were stacked next to each other.
Note that the floats are positioned
using their margin boxes,
not the <a>float area</a>.
<img class="singleImgExample" src="images/stacked-float-example.png" alt="Stacking two floats with a small shape-outside"/>
</div>
<h2 id="basic-shape-functions">
Basic Shapes</h2>
The <dfn><basic-shape></dfn> type
can be specified using basic shape functions.
When using this syntax
to define shapes,
the <dfn>reference box</dfn> is defined
by each property that uses
<<basic-shape>> values.
The coordinate system for the shape
has its origin on the top-left corner of the
<a>reference box</a> with the x-axis
running to the right
and the y-axis running downwards.
All the lengths expressed in percentages
are resolved from the used dimensions
of the <a>reference box</a>.
<h3 id="supported-basic-shapes">
Supported Shapes</h3>
The following shapes are supported.
All <<basic-shape>> values use
<a href="https://www.w3.org/TR/css3-values/#functional-notation">functional notation</a>
and are defined here using the
<a href="https://www.w3.org/TR/css3-values/#value-defs">Value Definition Syntax</a>.
<dl>
<dt><dfn>inset()</dfn> =
inset( <<length-percentage>>{1,4} [ round <<'border-radius'>> ]? )
</dt>
<dd>
Defines an inset rectangle.
<ul>
<li>
When all of the first four arguments
are supplied they represent the
<strong>top, right, bottom</strong> and
<strong>left</strong> offsets
from the <a>reference box</a> inward
that define the positions
of the edges
of the inset rectangle.
These arguments follow the syntax
of the 'margin' shorthand,
that let you set all four insets
with one, two or four values.
</li>
<li>
The optional <<'border-radius'>> argument(s)
define rounded corners for the inset rectangle
using the 'border-radius' shorthand syntax.
</li>
</ul>
A pair of insets in either dimension
that add up to more than the used dimension
(such as left and right insets of 75% apiece)
use the [[css-backgrounds-3#corner-overlap]] rules
to proportionally reduce the inset effect to 100%.
This will result in a shape edge positioned
within the reference box
(at 50%, in the case of two 75% inset values).
</dd>
<dt><dfn>circle()</dfn> =
circle( <<shape-radius>>? [ at <<position>> ]? )
</dt>
<dd>
<ul>
<li>
The shape-radius argument represents
<strong>r</strong>, the radius
of the circle.
Negative values are invalid.
A percentage value here
is resolved from the used width and height
of the <a>reference box</a> as <br>
<code>sqrt(<em>width</em><sup>2</sup>+<em>height</em><sup>2</sup>)/sqrt(2)</code>.
</li>
<li>
The position argument defines
the center of the circle.
This defaults to center if omitted.
</li>
</ul>
</dd>
<dt><dfn>ellipse()</dfn> =
ellipse( [ <<shape-radius>>{2} ]? [ at <<position>> ]? )
</dt>
<dd>
<ul>
<li>
The shape-radius arguments represent
<strong>rx</strong> and
<strong>ry</strong>,
the x-axis and y-axis radii
of the ellipse,
in that order.
Negative values for either radius are invalid.
Percentage values here are resolved
against the used width (for the rx value)
and the used height (for the ry value)
of the reference box.
</li>
<li>
The position argument defines
the center of the ellipse.
This defaults to center if omitted.
</li>
</ul>
</dd>
<dt><dfn>polygon()</dfn> =
polygon( <<'fill-rule'>>? , [<<length-percentage>> <<length-percentage>>]# )
</dt>
<dd>
<ul>
<li>
<<'fill-rule'>> -
The filling rule used
to determine the interior
of the polygon.
See <a href="https://www.w3.org/TR/SVG/painting.html#FillRuleProperty">fill-rule</a> property
in SVG for details.
Possible values are ''nonzero''
or ''evenodd''.
Default value when omitted is ''nonzero''.</li>
<li>
Each pair argument in the list represents <strong>x<sub>i</sub></strong> and <strong>y<sub>i</sub></strong> -
the <strong>x</strong> and <strong>y</strong> axis coordinates of the i-th vertex of the polygon.
</li>
</ul>
The UA must close a polygon
by connecting the last vertex
with the first vertex of the list.
</dd>
<dt><dfn>path()</dfn> =
path( [<<'fill-rule'>>,]? <<string>> )
</dt>
<dd dfn-type=value dfn-for="path()">
<ul>
<li>
<<'fill-rule'>> -
The filling rule used
to determine the interior
of the path.
See <a href="https://www.w3.org/TR/SVG/painting.html#FillRuleProperty">fill-rule</a> property
in SVG for details.
Possible values are ''nonzero''
or ''evenodd''.
Default value when omitted is ''nonzero''.
<li>
The <dfn><<string>></dfn> represents an
<a href="https://www.w3.org/TR/SVG11/paths.html#PathData">SVG Path data string</a>.
The path data string must be conform
to the grammar and parsing rules of SVG 1.1.
The initial position is defined
by the first “move to” argument
in the path string.
For the initial direction follow SVG 1.1.
</ul>
The UA must close a path
with an implicit
closepath command ("z" or "Z")
if it is not present in the string
for properties that require a closed loop
(such as 'shape-outside' and 'clip-path').
</dl>
The arguments not defined above are defined as follows:
<dl>
<dt><dfn><<shape-radius>></dfn> = <<length-percentage>> | closest-side | farthest-side
<dd>
Defines a radius for a circle or ellipse. If omitted it defaults to closest-side.
<ul>
<li>
<dfn>closest-side</dfn>
uses the length from the center
of the shape to the closest side
of the <a>reference box</a>.
For circles,
this is the closest side
in any dimension.
For ellipses,
this is the closest side
in the radius dimension.
<li>
<dfn>farthest-side</dfn>
uses the length from the center
of the shape to the farthest side
of the <a>reference box</a>.
For circles,
this is the farthest side
in any dimension.
For ellipses,
this is the farthest side
in the radius dimension.
</ul>
</dl>
<h3 id='basic-shape-computed-values'>
Computed Values of Basic Shapes</h3>
The values in a <<basic-shape>> function are computed as specified, with these exceptions:
<ul>
<li>
Omitted values are included and compute to their defaults.
</li>
<li>
A <<position>> value in ''circle()'' or ''ellipse()'' is computed as a pair of offsets (horizontal then vertical) from the top left origin, each given as a combination of an absolute length and a percentage.
</li>
<li>
A <<'border-radius'>> value in ''inset()'' is computed as an expanded list of all eight <<length-percentage>> values.
</li>
</ul>
<h3 id='basic-shape-serialization'>
Serialization of Basic Shapes</h3>
To serialize the <<basic-shape>> functions,
serialize as per their individual grammars,
in the order the grammars are written in,
avoiding calc() expressions where possible,
avoiding calc() transformations,
omitting components when possible without changing the meaning,
joining space-separated tokens with a single space,
and following each serialized comma with a single space.
<div class="example">
Since <<position>> keywords stand in for percentages, keywords without an offset turn into percentages.
<pre><code>
circle(at left bottom)
serializes as "circle(at 0% 100%)"
</code></pre>
Omitting components means that some default values do not show up in the serialization. But since <<position>> always uses the 2- or 4-value form, a default <<position>> is not omitted.
<pre><code>
circle(closest-side at center)
serializes as "circle(at 50% 50%)"
</code></pre>
Using grammar order means that <<position>> values always give horizontal components first, then vertical.
<pre><code>
circle(at bottom left)
serializes as "circle(at 0% 100%)"
</code></pre>
Avoiding calc() expressions means that some <<position>> values that could be simplified to the 2-value form must be serialized in 4-value form instead.
<pre><code>
circle(at right 5px bottom 10px)
serializes as "circle(at right 5px bottom 10px)"
not as "circle(at calc(100% - 5px) calc(100% - 10px))"
</code></pre>
Avoiding calc() transformations means that if a specified (or computed) calc() must stay in calc() form, it will be used as-is, not reformulated with a different origin or reduced.
<pre><code>
bottom calc(10% + 5px)
serializes as "bottom calc(10% + 5px)"
not as "top calc(90% - 5px)" or "calc(90% - 5px)"
</code></pre>
Preferring 0% over a zero length comes up when you must supply an omitted offset.
<pre><code>
circle(at right 5px top)
serializes as "circle(at right 5px top 0%)"
</code></pre>
Preferring left and top origins means that some percentage offsets will normalize to those origins (when calc can be avoided).
<pre><code>
circle(at right 5% top 0px)
serializes as "circle(at 95% 0%)"
</code></pre>
</div>
<h3 id='basic-shape-interpolation'>
Interpolation of Basic Shapes</h3>
For interpolating between
one basic shape and a second,
the rules below are applied.
The values in the shape functions interpolate
as a <a href="https://www.w3.org/TR/css3-transitions/#animtype-simple-list">simple list</a>.
The list values interpolate as
<a href="https://www.w3.org/TR/css3-transitions/#animtype-lpcalc">length,
percentage, or calc</a> where possible.
If list values are not one of those types
but are identical
(such as finding ''nonzero''
in the same list position
in both lists)
those values do interpolate.
<ul>
<li>
Both shapes must use the same <a>reference box</a>.
</li>
<li>
If both shapes are the same type,
that type is ''ellipse()'' or ''circle()'',
and none of the radii use
the <a href="#closest-side">''closest-side''</a> or <a href="#farthest-side">''farthest-side''</a> keywords,
interpolate between each value
in the shape functions.
</li>
<li>
If both shapes are of type ''inset()'',
interpolate between each value
in the shape functions.
</li>
<li>
If both shapes are of type ''polygon()'',
both polygons have the same number of vertices,
and use the same <<'fill-rule'>>,
interpolate between each value
in the shape functions.
</li>
<li>
In all other cases no interpolation is specified.
</li>
</ul>
<h2 id="shapes-from-image">
Shapes from Image</h2>
Another way of defining shapes
is by specifying a source <<image>>
whose alpha channel is used
to compute the shape.
The shape is computed to be the path or paths
that enclose the area(s)
where the opacity of the specified image
is greater than the 'shape-image-threshold' value.
The absence of any pixels with an alpha value
greater than the specified threshold
results in an empty float area that will not affect wrapping.
If the 'shape-image-threshold' is not specified,
the initial value to be considered is 0.0.
The image is sized and positioned
as if it were a replaced element
whose specified width and height
are the same as the element's
used content box size.
For animated raster image formats (such as
<a href="http://www.w3.org/Graphics/GIF/spec-gif89a.txt">GIF</a>),
the first frame of the animation sequence is used.
<div class="example">
An image is floating to the left of a paragraph.
The image shows the 3D version of the
CSS logo over a transparent background.
The logo has a shadow using an alpha-channel.
The image defines its <a>float area</a>
through the 'shape-outside' property.
<pre>
<code>
<p>
<img id="CSSlogo" src="CSS-logo1s.png"/>
blah blah blah blah...
</p>
<style>
#CSSlogo {
float: left;
shape-outside: attr(src url);
shape-image-threshold: 0.1;
}
</style>
</code>
</pre>
The 'shape-outside' property re-uses the url
from the src attribute of the img element.
It is perfectly possible to display an image
and use a different image for its <a>float area</a>.
In the figure below, the alpha-channel threshold
is represented by the dotted line around the CSS logo.
It's then possible to affect where the lines
of the paragraph start in three ways:
<ol>
<li>Modifying the alpha channel in the image</li>
<li>Changing the value of the 'shape-image-threshold' property</li>
<li>Changing the value of the 'shape-margin' property (see example 8)</li>
</ol>
<figure>
<img alt="A float shape around an image using its alpha-channel" src="images/shape-outside-image.png" style="width:70%"/>
<figcaption>
A float shape around an image using its alpha-channel.
</figcaption>
</figure>
</div>
<h2 id="shapes-from-box-values">
Shapes from Box Values</h2>
Shapes can be defined
by reference to edges in the
<a href="https://www.w3.org/TR/css-box-3/#the-css-box-model">CSS Box Model</a>.
These edges include
<a href="https://www.w3.org/TR/css3-background/#corner-shaping">border-radius curvature</a> [[!CSS3BG]]
from the used border-radius values.
The <<shape-box>> value extends the <<box>> value
to include ''margin-box''.
Its syntax is:
<pre>
<dfn><<shape-box>></dfn> = <<box>> | ''margin-box''
</pre>
The definitions of the values are:
The <dfn value for="<shape-box>, shape-outside">margin-box</dfn> value defines the shape
enclosed by the outside margin edge.
The corner radii of this shape are determined
by the corresponding border-radius and margin values.
If the ratio of <code>border-radius/margin</code> is 1 or more,
or margin is negative or zero,
then the margin box corner radius is
<code>max(border-radius + margin, 0)</code>.
If the ratio of <code>border-radius/margin</code> is less than 1,
and margin is positive,
then the margin box corner radius is
<code>border-radius + margin * (1 + (ratio-1)^3)</code>.
The <dfn value for="<shape-box>, shape-outside">border-box</dfn> value defines the shape
enclosed by the outside border edge.
This shape follows all
of the normal border radius shaping rules
for the outside of the border.
The <dfn value for="<shape-box>, shape-outside">padding-box</dfn> value defines the shape
enclosed by the outside padding edge.
This shape follows all
of the normal border radius shaping rules
for the inside of the border.
The <dfn value for="<shape-box>, shape-outside">content-box</dfn> value defines the shape
enclosed by the outside content edge.
Each corner radius of this box
is the larger of 0
or <code>border-radius - border-width - padding</code>.
<div class="example">
Given the 100px square below with
10px padding, border and margins,
the box values define these shapes:
<ul>
<li>''margin-box'': the shape containing all of the yellow pixels</li>
<li>''border-box'': the shape containing all of the black pixels</li>
<li>''padding-box'': the shape containing all of the mauve pixels</li>
<li>''content-box'': the shape containing all of the blue pixels</li>
</ul>
<figure>
<img alt="Colored boxes representing simple box edges" src="images/box-edges-simple.png"/>
<figcaption>
Simple CSS Box Model Edges
</figcaption>
</figure>
And the same definitions apply to a more complex example with the same 100px square, but with these border, padding and margin properties:
<pre>
<code>
border-radius: 20px 20px 20px 40px;
border-width: 30px 10px 20px 10px;
padding: 10px 20px 10px 10px;
margin: 20px 10px 10px 10px;
</code>
</pre>
<figure>
<img alt="Colored boxes representing complex box edges" src="images/box-edges-complex.png"/>
<figcaption>
Complex CSS Box Model Edges
</figcaption>
</figure>
</div>
<div class="example">
The difference between normal float wrapping
and wrapping around the shape defined
by the margin-box value is that
the margin-box shape includes corner shaping.
Take the 100px square with 10px padding,
border and margins,
but with a border-radius of 60px.
If you make a left float out of it,
content normally wraps in this manner:
<figure>
<img alt="Text wrapping around float with no shape" src="images/normal-wrap.png"/>
<figcaption>
Normal float wrapping
</figcaption>
</figure>
If you add a margin-box shape to the float,
then content wraps around the rounded margin-box corners.
<pre>
<code>
shape-outside: margin-box;
</code>
</pre>
<figure>
<img alt="Text wrapping around float with margin-box shape" src="images/margin-box-wrap.png"/>
<figcaption>
Float wrapping with margin-box
</figcaption>
</figure>
</div>
<h2 id="declaring-shapes">
Declaring Shapes</h2>
Shapes are declared with
the 'shape-outside' property,
with possible modifications
from the 'shape-margin' property.
The shape defined by
the 'shape-outside'
and 'shape-margin' properties
changes the geometry
of a float element's
<a>float area</a>.
<h3 id="shape-outside-property">
Float Area Shape: the 'shape-outside' property</h3>
<pre class='propdef'>
Name: shape-outside
Value: none | [ <<basic-shape>> || <<shape-box>> ] | <<image>>
Initial: none
Applies to: floats
Inherited: no
Computed value: as <a href="#basic-shape-computed-values">defined</a> for <<basic-shape>> (with <<shape-box>> following, if supplied); else the computed <<image>>; else the keyword as specified
Animation type: as <a href="#basic-shape-interpolation">defined</a> for <<basic-shape>>, otherwise discrete
</pre>
The values of this property have the following meanings:
<dl dfn-type="value" dfn-for="shape-outside">
<dt><dfn>none</dfn></dt>
<dd>
The <a>float area</a> is unaffected.
</dd>
<dt><<shape-box>></dt>
<dd>
If one of these values is specified by itself
the shape is computed based on one of
''margin-box'',
''border-box'',
''padding-box'' or
''content-box''
which use their respective boxes
including curvature from border-radius,
similar to 'background-clip' [[!CSS3BG]].
</dd>
<dt><dfn><<basic-shape>></dfn></dt>
<dd>
The shape is computed based on the values of one
of ''inset()'', ''circle()'', ''ellipse()''
or ''polygon()''. If a <<shape-box>> is also supplied, this defines the <a>reference box</a> for the <<basic-shape>> function. If <<shape-box>> is not supplied, then the <a>reference box</a> defaults to ''margin-box''.
</dd>
<dt><dfn><<image>></dfn></dt>
<dd>
The shape is extracted
and computed based
on the alpha channel
of the specified <<image>>
as defined by 'shape-image-threshold'.
User agents must use the
<a href="https://www.w3.org/TR/html5/infrastructure.html#cors-enabled-fetch">potentially CORS-enabled fetch</a>
method defined by the [[!HTML5]] specification
for all URLs in a 'shape-outside' value.
When fetching,
user agents must use "Anonymous" mode,
set the referrer source
to the stylesheet's URL
and set the origin to the URL
of the containing document.
If this results in network errors
such that there is no valid fallback image,
the effect is as if
the value <a value for="shape-outside">none</a>
had been specified.
</dd>
</dl>
<h3 id="shape-image-threshold-property">
Choosing Image Pixels: the 'shape-image-threshold' property</h3>
The 'shape-image-threshold'
defines the alpha channel threshold
used to extract the shape
using an image.
A value of 0.5 means that
the shape will enclose
all the pixels
that are more than 50% opaque.
<pre class='propdef'>
Name: shape-image-threshold
Value: <<alpha-value>>
Initial: 0
Applies to: floats
Inherited: no
Computed value: specified number, clamped to the range [0,1]
Animation type: by computed value
</pre>
The values of this property have the following meanings:
<dl dfn-type="value" dfn-for="shape-image-threshold">
<dt><dfn><<number>></dfn></dt>
<dd>
Sets the threshold used
for extracting a shape
from an image.
The shape is defined
by the pixels whose alpha value
is greater than the threshold.
A threshold value outside the range
0.0 (fully transparent)
to 1.0 (fully opaque)
will be clamped to this range.
</dd>
</dl>
Note: A future level of CSS Shapes may define
a switch to use the luminance data
from an image instead of the alpha data.
When this happens,
shape-image-threshold will be extended
to apply its threshold
to either alpha or luminance,
depending on the switch state.
<h3 id="shape-margin-property">
Expanding a Shape: the 'shape-margin' property</h3>
The 'shape-margin' property adds
a margin to a 'shape-outside'.
This defines a new shape
that is the smallest contour
(in the shrink-wrap sense)
that includes all the points