-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathvisudet.src
1552 lines (1347 loc) · 63.8 KB
/
visudet.src
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">
<!-- $Id: visudet.src,v 2.173 2012-08-21 13:58:40 bbos Exp $ -->
<head>
<title>Visual formatting model details</title>
<!--script src="http://www.w3c-test.org/css/harness/annotate.js#CSS21_DEV" type="text/javascript" defer></script-->
<style type="text/css">
.current,.proposed,span.delcurrent,div.delcurrent { background:#feb }
ins.proposed,span.insproposed,li.insproposed,div.insproposed { background:#bfb }
del.proposed,span.delproposed { background:#fbb }
span.insproposed,li.insproposed,div.insproposed { text-decoration:underline }
span.delproposed,span.delcurrent,div.delcurrent { text-decoration:line-through }
body>del,body>ins {display:block}
</style>
</head>
<body>
<h1>Visual formatting model details</h1>
<h2><a name="containing-block-details">Definition of "containing
block"</a></h2>
<p>The position and size of an element's box(es) are sometimes
calculated relative to a certain rectangle, called the <dfn><span
class="index-def" title="containing block">containing
block</span></dfn> of the element. The containing block of an element
is defined as follows:</p>
<ol>
<li>The containing block in which the <a href="conform.html#root">root
element</a> lives is a rectangle called the <dfn><span
class="index-def" title="initial containing block|containing
block::initial">initial containing block</span></dfn>. For continuous
media, it has the dimensions of the <a
href="visuren.html#viewport">viewport</a> and is anchored at the
canvas origin; it is the <a href="page.html#page-area">page area</a>
for paged media. The 'direction' property of the initial
containing block is the same as for the root element.
</li>
<li>For other elements, if the element's position is 'relative' or 'static',
the containing block is formed by the content edge of the nearest
ancestor box that is a <a href="visuren.html#block-boxes">block
container</a> or which establishes a formatting context.
</li>
<li>If the element has 'position: fixed', the containing block is
established by the <a href="visuren.html#viewport">viewport</a>
in the case of continuous media or the page area in the case of paged media.
</li>
<li>If the element has 'position: absolute', the containing block is
established by the nearest ancestor with a <span
class="propinst-position">'position'</span> of 'absolute', 'relative'
or 'fixed', in the following way:
<ol>
<li>In the case that the ancestor is an inline element, the containing
block is the bounding box around the padding boxes of the first and
the last inline boxes
generated for that element. In CSS 2.2, if the inline
element is split
across multiple lines, the containing block is undefined.
</li>
<li>Otherwise, the containing block
is formed by the <a href="box.html#padding-edge">padding edge</a> of
<!-- we probably mean: the principal box of -->
the ancestor.
</li>
</ol>
<p>If there is no such ancestor, the containing block is the initial
containing block.
</p>
</li>
</ol>
<p>In paged media, an absolutely positioned element is positioned
relative to its containing block ignoring any page breaks (as if the
document were continuous). The element may subsequently be broken over
several pages.
</p>
<p>For absolutely positioned content that resolves to a position on a
page other than the page being laid out (the current page), or
resolves to a position on the current page which has already been
rendered for printing, printers may place the content
<ul>
<li>on another location on the current page,
<li>on a subsequent page, or
<li>may omit it.
</ul>
<p class="note">Note that a
block-level element that is split over several pages may have a different
width on each page and that there may be device-specific limits.
</p>
<div class="example">
<p>With no positioning, the containing blocks (C.B.) in the
following document:</p>
<pre class="html example">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<TITLE>Illustration of containing blocks</TITLE>
</HEAD>
<BODY id="body">
<DIV id="div1">
<P id="p1">This is text in the first paragraph...</P>
<P id="p2">This is text <EM id="em1"> in the
<STRONG id="strong1">second</STRONG> paragraph.</EM></P>
</DIV>
</BODY>
</HTML>
</pre>
<p>are established as follows:</p>
<table border="1">
<tr><th>For box generated by </th>
<td><strong>C.B. is established by</strong></td></tr>
<tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
<tr><td>body</td><td>html</td></tr>
<tr><td>div1</td><td>body</td></tr>
<tr><td>p1</td><td>div1</td></tr>
<tr><td>p2</td><td>div1</td></tr>
<tr><td>em1</td><td>p2</td></tr>
<tr><td>strong1</td><td>p2</td></tr>
</table>
<p>If we position "div1":</p>
<pre class="example">
#div1 { position: absolute; left: 50px; top: 50px }
</pre>
<p>its containing block is no longer "body"; it becomes
the initial containing block (since there are no
other positioned ancestor boxes).
</p>
<p>If we position "em1" as well:</p>
<pre class="example">
#div1 { position: absolute; left: 50px; top: 50px }
#em1 { position: absolute; left: 100px; top: 100px }
</pre>
<p>the table of containing blocks becomes:</p>
<table border="1">
<tr><th>For box generated by</th>
<td><strong>C.B. is established by</strong></td></tr>
<tr><td>html</td><td>initial C.B. (UA-dependent)</td></tr>
<tr><td>body</td><td>html</td></tr>
<tr><td>div1</td><td>initial C.B.</td></tr>
<tr><td>p1</td><td>div1</td></tr>
<tr><td>p2</td><td>div1</td></tr>
<tr><td>em1</td><td>div1</td></tr>
<tr><td>strong1</td><td>em1</td></tr>
</table>
<p>By positioning "em1", its containing block becomes
the nearest positioned ancestor box (i.e., that generated
by "div1").
</p>
</div>
<h2><a name="the-width-property">Content width</a>: the <span
class="propinst-width">'width'</span> property</h2>
<!-- #include src=properties/width.srb -->
<p> This property specifies the <a
href="box.html#content-width">content width</a> of boxes.
</p>
<p>This property does not apply to non-replaced <a
href="visuren.html#inline-boxes">inline</a> elements. The
content width
of a non-replaced inline element's boxes is that of the rendered
content within them (<em>before</em> any relative offset of
children). Recall that inline boxes flow into <a
href="visuren.html#line-box">line boxes</a>. The width of line boxes
is given by the their <a
href="visuren.html#containing-block">containing block</a>, but may be
shorted by the presence of <a href="visuren.html#floats">floats</a>.
</p>
<p>Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="<length>"><span class="value-inst-length"><strong><length></strong></span></span>
</dt>
<dd>Specifies the width of the content area using a length unit.
</dd>
<dt><span class="index-inst" title="<percentage>"><span class="value-inst-percentage"><strong><percentage></strong></span></span>
</dt>
<dd>Specifies a percentage width. The percentage is calculated
with respect to the width of the generated box's
<a href="visuren.html#containing-block">containing block</a>.
If the containing block's width depends on this element's width, then
the resulting layout is undefined in CSS 2.2.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block container element, the percentage is calculated with
respect to the width of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage width was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><strong>auto</strong>
</dt>
<dd>The width depends on the values of other properties.
See the sections below.
</dd>
</dl>
<p>Negative values for <span class="propinst-width">'width'</span> are
illegal.
</p>
<div class="example"><p>
For example, the following rule fixes the content width of paragraphs
at 100 pixels:</p>
<pre>
p { width: 100px }
</pre>
</div>
<h2><a name="Computing_widths_and_margins">Calculating widths and
margins</a></h2>
<p>The values of an element's <span
class="propinst-width">'width'</span>, <span
class="propinst-margin-left">'margin-left'</span>, <span
class="propinst-margin-right">'margin-right'</span>, <span
class="propinst-left">'left'</span> and <span
class="propinst-right">'right'</span> properties as used for layout
depend on the type of box generated and on each other. (The value used
for layout is sometimes referred to as the <a
href="cascade.html#usedValue">used value</a>.) In
principle, the values used are the same as the computed values, with
'auto' replaced by some suitable value, and percentages calculated
based on the containing block, but there are exceptions. The following
situations need to be distinguished:</p>
<ol>
<li>inline, non-replaced elements</li>
<li>inline, replaced elements</li>
<li>block-level, non-replaced elements in normal flow</li>
<li>block-level, replaced elements in normal flow</li>
<li>floating, non-replaced elements</li>
<li>floating, replaced elements</li>
<li>absolutely positioned, non-replaced elements</li>
<li>absolutely positioned, replaced elements</li>
<li>'inline-block', non-replaced elements in normal flow</li>
<li>'inline-block', replaced elements in normal flow</li>
</ol>
<p>For Points 1-6 and 9-10, the values of 'left' and 'right' in the
case of relatively positioned elements are determined by the rules in <a
href="visuren.html#relative-positioning">section 9.4.3.</a>
</p>
<p class=note><em><strong>Note.</strong> The used value of 'width'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on <span
class="propinst-min-width">'min-width'</span> and <span
class="propinst-max-width">'max-width'</span>, see the section <a
href="#min-max-widths">Minimum and maximum widths</a> below.</em>
<h3><a name="inline-width">Inline, non-replaced elements</a></h3>
<p>The <span class="propinst-width">'width'</span> property does not
apply. A computed value of 'auto' for <span
class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> becomes a used
value of '0'.
</p>
<h3><a name="inline-replaced-width">Inline, replaced elements</a></h3>
<p>A computed value of 'auto' for <span
class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> becomes a used
value of '0'.
<p>If <span class="propinst-height">'height'</span> and <span
class="propinst-width">'width'</span> both have computed values of
'auto' and the element also has an intrinsic width, then that
intrinsic width is the used value of <span
class="propinst-width">'width'</span>.
<p>If <span class="propinst-height">'height'</span> and <span
class="propinst-width">'width'</span> both have computed values of
'auto' and the element has no intrinsic width, but does have an
intrinsic height and intrinsic ratio; or if <span
class="propinst-width">'width'</span> has a computed value of 'auto',
<span class="propinst-height">'height'</span> has some other computed
value, and the element does have an intrinsic ratio; then the used
value of <span class="propinst-width">'width'</span> is:
<blockquote><p>(used height) * (intrinsic ratio)</blockquote>
<p>If 'height' and <span class="propinst-width">'width'</span> both
have computed values of 'auto' and the element has an intrinsic ratio
but no intrinsic height or width, then the used value of 'width' is
undefined in CSS 2.2.
However, it is suggested that, if the containing block's width
does not itself depend on the replaced element's width, then the used
value of 'width' is calculated from the constraint equation used for
block-level, non-replaced elements in normal flow.
<p>Otherwise, if <span class="propinst-width">'width'</span> has a
computed value of 'auto', and the element has an intrinsic width, then
that intrinsic width is the used value of <span
class="propinst-width">'width'</span>.
<p>Otherwise, if <span class="propinst-width">'width'</span> has a
computed value of 'auto', but none of the conditions above are met,
then the used value of <span class="propinst-width">'width'</span>
becomes 300px. If 300px is too wide to fit the device, UAs should use
the width of the largest rectangle that has a 2:1 ratio and fits the
device instead.
<h3><a name="blockwidth">Block-level, non-replaced elements in normal
flow</a></h3>
<p>The following <a name="width-constraints">constraints</a> must hold
among the used values of the other properties:</p>
<blockquote>
<p><span class="propinst-margin-left">'margin-left'</span> + <span
class="propinst-border-left-width">'border-left-width'</span> + <span
class="propinst-padding-left">'padding-left'</span> + <span
class="propinst-width">'width'</span> + <span
class="propinst-padding-right">'padding-right'</span> + <span
class="propinst-border-right-width">'border-right-width'</span> +
<span class="propinst-margin-right">'margin-right'</span> = width of <a
href="#containing-block-details">containing block</a>
</p>
</blockquote>
<p>If 'width' is not 'auto' and 'border-left-width' + 'padding-left' +
'width' + 'padding-right' + 'border-right-width' (plus any of
'margin-left' or 'margin-right' that are not 'auto') is larger than
the width of the containing block, then any 'auto' values for
'margin-left' or 'margin-right' are, for the following rules, treated
as zero.
</p>
<p>If
all of the above have a computed value other than 'auto', the values
are said to be "over-constrained" and one of the used values will
have to be different from its computed value. If the <span
class="propinst-direction">'direction'</span>
property of the containing block has the value 'ltr', the specified
value of <span
class="propinst-margin-right">'margin-right'</span> is ignored and the
value is calculated so as to make the equality true. If the value of
<span class="propinst-direction">'direction'</span> is 'rtl', this
happens to <span class="propinst-margin-left">'margin-left'</span> instead.
</p>
<p>If there is exactly one value specified as 'auto', its used
value follows from the equality.
</p>
<p>If <span class="propinst-width">'width'</span> is set to 'auto',
any other 'auto' values become '0' and <span
class="propinst-width">'width'</span> follows from the resulting
equality.
</p>
<p>If both <span class="propinst-margin-left">'margin-left'</span> and
<span class="propinst-margin-right">'margin-right'</span> are 'auto',
their used values are equal. This horizontally centers the element
with respect to the edges of the containing block.
</p>
<h3><a name="block-replaced-width">Block-level, replaced elements in normal flow</a></h3>
<p>The used value of
<span class="propinst-width">'width'</span> is determined
as for <a href="#inline-replaced-width">inline replaced
elements</a>.
Then the rules <a href="#blockwidth">for non-replaced
block-level elements</a> are applied to determine the margins.
</p>
<h3><a name="float-width">Floating, non-replaced elements</a></h3>
<p>If <span
class="propinst-margin-left">'margin-left'</span>, or <span
class="propinst-margin-right">'margin-right'</span> are computed as
'auto', their used value is '0'.
</p>
<p>If <span class="propinst-width">'width'</span> is computed as
'auto', the used value is the "shrink-to-fit" width.
</p>
<p><a name="shrink-to-fit-float"></a> Calculation of the shrink-to-fit
width is similar to calculating the width of a table cell using the
automatic table layout algorithm. Roughly: calculate the preferred
width by formatting the content without breaking lines other than
where explicit line breaks occur, and also calculate the preferred
<em>minimum</em> width, e.g., by trying all possible line breaks.
CSS 2.2 does not define the exact algorithm. Thirdly, find the
<em>available width</em>: in this case, this is the width of the
containing block minus the used values of 'margin-left',
'border-left-width', 'padding-left', 'padding-right',
'border-right-width', 'margin-right', and the widths of any relevant
scroll bars.
</p>
<p>Then the shrink-to-fit width is: min(max(preferred minimum width,
available width), preferred width).</p>
<h3><a name="float-replaced-width">Floating, replaced elements</a></h3>
<p>If <span class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> are computed as
'auto', their used value is '0'. The used value of <span
class="propinst-width">'width'</span> is determined as for <a
href="#inline-replaced-width">inline replaced elements</a>.
</p>
<h3><a name="abs-non-replaced-width">Absolutely positioned, non-replaced elements</a></h3>
<p>For the purposes of this section and the next, the term <a
name=static-position><span class=index>"static position"</span></a>
(of an element) refers, roughly,
to the position an element would have had in the normal flow. More
precisely:
</p>
<ul>
<li>The <dfn>static-position containing block</dfn> is the containing
block of a hypothetical box that would have been the first box of the
element if its specified <span
class="propinst-position">'position'</span> value had been 'static'
and its specified 'float' had been 'none'. (Note that due to the rules
in <a href="visuren.html#dis-pos-flo">section 9.7</a> this
hypothetical calculation might require also assuming a different
computed value for 'display'.)
</li>
<li>The static position for 'left' is the distance from the left edge
of the containing block to the left margin edge of a hypothetical box
that would have been the first box of the element if its <span
class="propinst-position">'position'</span> property had been 'static'
and <span class="propinst-float">'float'</span> had been 'none'. The
value is negative if the hypothetical
box is to the left of the containing block.
</li>
<li>The static position for 'right' is the distance from the right
edge of the containing block to the right margin edge of the same
hypothetical box as above. The value is positive if the hypothetical
box is to the left of the containing block's edge.
</li>
</ul>
<p>But rather than actually calculating the dimensions of that
hypothetical box, user agents are free to make a guess at its probable
position.
</p>
<p>For the purposes of calculating the static position, the containing
block of fixed positioned elements is the initial containing block
instead of the viewport, and all scrollable boxes should be assumed to
be scrolled to their origin.
<p>The constraint that determines the used values for these
elements is:</p>
<blockquote>
<p>'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width'
+ 'padding-right' + 'border-right-width' + 'margin-right' + 'right' = width
of containing block </p>
</blockquote>
<p>If all three of 'left', 'width', and 'right' are 'auto': First set
any 'auto' values for 'margin-left' and 'margin-right' to 0. Then, if
the 'direction' property of the element establishing the
static-position containing block is 'ltr' set 'left'
to the <a
href="#static-position">static position</a> and apply rule number
three below; otherwise, set 'right' to the <a
href="#static-position">static position</a> and apply rule number
one below.</p>
<p>If none of the three is 'auto': If both 'margin-left' and
'margin-right' are 'auto', solve the
equation under the extra constraint that the two margins get equal
values, unless this would make them negative, in which case when
direction of the containing block is 'ltr' ('rtl'), set 'margin-left'
('margin-right') to zero
and solve for 'margin-right' ('margin-left'). If one of
'margin-left' or 'margin-right' is 'auto', solve the equation for that
value. If the values are over-constrained, ignore the value for 'left'
(in case the 'direction' property of the containing block is 'rtl') or
'right' (in case 'direction' is
'ltr') and solve for that value.</p>
<p>Otherwise, set 'auto' values for 'margin-left' and 'margin-right'
to 0, and pick the one of the following six rules that applies.</p>
<ol>
<li>'left' and 'width' are 'auto' and 'right' is not 'auto', then the
width is shrink-to-fit. Then solve for 'left'</li>
<li>'left' and 'right' are 'auto' and 'width' is not 'auto', then if
the 'direction' property of the element establishing the
static-position containing block is 'ltr' set 'left'
to the <a
href="#static-position">static position</a>, otherwise set 'right'
to the <a href="#static-position">static position</a>. Then solve
for 'left' (if 'direction is 'rtl') or 'right' (if 'direction' is
'ltr').</li>
<li>'width' and 'right' are 'auto' and 'left' is not 'auto', then the
width is shrink-to-fit . Then solve for 'right'</li>
<li>'left' is 'auto', 'width' and 'right' are not 'auto', then solve for
'left'</li>
<li>'width' is 'auto', 'left' and 'right' are not 'auto', then solve
for 'width'</li>
<li>'right' is 'auto', 'left' and 'width' are not 'auto', then solve
for 'right'</li>
</ol>
<p>Calculation of the shrink-to-fit width is similar to calculating
the width of a table cell using the automatic table layout algorithm.
Roughly: calculate the preferred width by formatting the content
without breaking lines other than where explicit line breaks occur,
and also calculate the preferred <em>minimum</em> width, e.g., by
trying all possible line breaks. CSS 2.2 does not define the
exact algorithm. Thirdly, calculate the <em>available width</em>: this
is found by solving for 'width' after setting 'left' (in case 1) or
'right' (in case 3) to 0.</p>
<p>Then the shrink-to-fit width is: min(max(preferred minimum width, available
width), preferred width).</p>
<h3><a name="abs-replaced-width">Absolutely positioned, replaced elements</a></h3>
<p>In this case, <a href="#abs-non-replaced-width">section 10.3.7</a>
applies up through and including the constraint equation, but the rest
of <a href="#abs-non-replaced-width">section 10.3.7</a> is replaced by
the following rules:
<ol>
<li>The used value of <span class="propinst-width">'width'</span> is
determined as for <a href="#inline-replaced-width">inline replaced
elements</a>.
If <span class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> is specified as
'auto' its used value is determined by the rules below.
</li>
<li>If both <span class="propinst-left">'left'</span> and <span
class="propinst-right">'right'</span> have the value 'auto', then if
the 'direction' property of the element establishing the
static-position containing block is 'ltr', set <span
class="propinst-left">'left'</span> to
the static position; else if 'direction' is 'rtl', set <span
class="propinst-right">'right'</span> to the static position.
</li>
<li>If <span class="propinst-left">'left'</span> or <span
class="propinst-right">'right'</span> are 'auto', replace any 'auto'
on <span class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> with '0'.
</li>
<li>If at this point both <span
class="propinst-margin-left">'margin-left'</span> and <span
class="propinst-margin-right">'margin-right'</span> are still 'auto',
solve the equation under the extra constraint that the two margins
must get equal values, unless this would make them negative, in which
case when the direction of the containing block is 'ltr' ('rtl'), set
<span
class="propinst-margin-left">'margin-left'</span> (<span
class="propinst-margin-right">'margin-right'</span>) to zero and solve
for <span class="propinst-margin-right">'margin-right'</span> (<span
class="propinst-margin-left">'margin-left'</span>).
</li>
<li>If at this point there is an 'auto' left, solve the equation
for that value.
</li>
<li>If at this point the values are over-constrained, ignore the value
for either <span class="propinst-left">'left'</span> (in case the
<span class="propinst-direction">'direction'</span> property of the
containing block is 'rtl') or <span
class="propinst-right">'right'</span> (in case <span
class="propinst-direction">'direction'</span> is 'ltr') and solve for
that value.
</li>
</ol>
<h3><a name="inlineblock-width">'Inline-block', non-replaced elements in normal flow</a></h3>
<p>If <span class="propinst-width">'width'</span> is 'auto', the
used value is the <a href="#shrink-to-fit-float">shrink-to-fit</a>
width as for floating elements.
</p>
<p>A computed value of 'auto' for <span
class="propinst-margin-left">'margin-left'</span> or <span
class="propinst-margin-right">'margin-right'</span> becomes a used
value of '0'.
</p>
<h3><a name="inlineblock-replaced-width">'Inline-block', replaced elements in normal flow</a></h3>
<p>Exactly as <a href="#inline-replaced-width">inline replaced
elements.</a>
</p>
<h2><a name="min-max-widths">Minimum and maximum widths</a>: <span
class="propinst-min-width">'min-width'</span> and <span
class="propinst-max-width">'max-width'</span></h2>
<!-- #include src=properties/min-width.srb -->
<!-- #include src=properties/max-width.srb -->
<p>These two properties allow authors to constrain content widths to a
certain range. Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="<length>"><span class="value-inst-length"><strong><length></strong></span></span>
</dt>
<dd>Specifies a fixed minimum or maximum used width.
</dd>
<dt><span class="index-inst" title="<percentage>"><span class="value-inst-percentage"><strong><percentage></strong></span></span>
</dt>
<dd>Specifies a percentage for determining the used value. The
percentage is calculated with respect to the width of the generated
box's <a href="visuren.html#containing-block">containing block</a>.
If the containing block's width is negative, the used value is
zero.
If the containing block's width depends on this element's width,
then the resulting layout is undefined in CSS 2.2.
</dd>
<dt><strong>none</strong>
</dt>
<dd>(Only on <span class="propinst-max-width">'max-width'</span>) No
limit on the width of the box.
</dd>
</dl>
<p>Negative values for <span
class="propinst-min-width">'min-width'</span> and <span
class="propinst-max-width">'max-width'</span> are illegal.
</p>
<p>In CSS 2.2, the effect of 'min-width' and 'max-width' on
tables, inline tables,
table cells, table columns, and column groups is undefined.
<p>The following algorithm describes how the two properties influence
the <a href="cascade.html#computed-value">used value</a>
of the <span class="propinst-width">'width'</span> property:</p>
<ol>
<li>The tentative used width is calculated (without <span
class="propinst-min-width">'min-width'</span> and <span
class="propinst-max-width">'max-width'</span>) following the rules
under <a href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above.
</li>
<li>If the tentative used width is greater than <span
class="propinst-max-width">'max-width'</span>, the rules <a
href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the computed value of <span
class="propinst-max-width">'max-width'</span> as the computed value
for <span class="propinst-width">'width'</span>.
</li>
<li>If the resulting width is smaller than <span
class="propinst-min-width">'min-width'</span>, the rules <a
href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the value of <span
class="propinst-min-width">'min-width'</span> as the computed value
for <span class="propinst-width">'width'</span>.
</li>
</ol>
<p class="note">These steps do not affect the real computed values of
the above properties.</p>
<p>However, for replaced elements with an intrinsic ratio and both
<span
class="propinst-width">'width'</span> and <span
class="propinst-height">'height'</span> specified as 'auto', the
algorithm is as follows:
</p>
<p>Select from the table the resolved height and width values for the
appropriate constraint violation. Take the <var>max-width</var> and
<var>max-height</var> as max(min, max) so that <var>min</var> ≤
<var>max</var> holds true.
In this table <var>w</var> and <var>h</var> stand for the results of
the width and height computations ignoring the <span
class="propinst-min-width">'min-width'</span>, <span
class="propinst-min-height">'min-height'</span>, <span
class="propinst-max-width">'max-width'</span> and <span
class="propinst-max-height">'max-height'</span> properties. Normally
these are the intrinsic width and height, but they may not be in the
case of replaced elements with intrinsic ratios.
<p class=note>Note: In cases where an explicit width or height is
set and the other dimension is auto, applying a minimum or maximum
constraint on the auto side can cause an over-constrained situation.
The spec is clear in the behavior but it might not be what the author
expects. The CSS3 object-fit property can be used to obtain different
results in this situation.
<table rules=all>
<thead>
<tr><th>Constraint Violation</th><th>Resolved Width</th><th>Resolved Height</th></tr>
</thead>
<tbody>
<tr><td>none</td>
<td><var>w</var></td>
<td><var>h</var></td></tr>
<tr><td><var>w > max-width</var></td>
<td><var>max-width</var></td>
<td><var>max(max-width * h/w, min-height)</var></td></tr>
<tr><td><var>w < min-width</var></td>
<td><var>min-width</var></td>
<td><var>min(min-width * h/w, max-height)</var></td></tr>
<tr><td><var>h > max-height</var></td>
<td><var>max(max-height * w/h, min-width)</var></td>
<td><var>max-height</var></td></tr>
<tr><td><var>h < min-height</var></td>
<td><var>min(min-height * w/h, max-width)</var></td>
<td><var>min-height</var></td></tr>
<tr><td>(<var>w > max-width</var>) and (<var>h > max-height</var>), where (<var>max-width/w ≤ max-height/h</var>)</td>
<td><var>max-width</var></td>
<td><var>max(min-height, max-width * h/w)</var></td></tr>
<tr><td>(<var>w > max-width</var>) and (<var>h > max-height</var>), where (<var>max-width/w > max-height/h</var>)</td>
<td><var>max(min-width, max-height * w/h)</var></td>
<td><var>max-height</var></td></tr>
<tr><td>(<var>w < min-width</var>) and (<var>h < min-height</var>), where (<var>min-width/w ≤ min-height/h</var>)</td>
<td><var>min(max-width, min-height * w/h)</var></td>
<td><var>min-height</var></td></tr>
<tr><td>(<var>w < min-width</var>) and (<var>h < min-height</var>), where (<var>min-width/w > min-height/h</var>)</td>
<td><var>min-width</var></td>
<td><var>min(max-height, min-width * h/w)</var></td></tr>
<tr><td>(<var>w < min-width</var>) and (<var>h > max-height</var>)</td>
<td><var>min-width</var></td>
<td><var>max-height</var></td></tr>
<tr><td>(<var>w > max-width</var>) and (<var>h < min-height</var>)</td>
<td><var>max-width</var></td>
<td><var>min-height</var></td></tr>
</tbody>
</table>
<p>Then apply the rules under <a
href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above, as if <span class="propinst-width">'width'</span>
were computed as this value.
<!--
<ol>
<li>Select from the following list of width-height pairs (a, b) the
first one that satisfies the two constraints min-width ≤ a
≤ max(min-width, max-width) and min-height ≤ b ≤
max(min-height, max-height). The resulting pair gives the used width
and height for the element. In this list, Wi and Hi stand for the
intrinsic width and height, respectively.
<ol>
<li>(Wi, Hi)</li>
<li>(max(Wi, min-width), max(Wi, min-width)*Hi/Wi)</li>
<li>(max(Hi, min-height)*Wi/Hi, max(Hi, min-height))</li>
<li>(min(Wi, max-width), min(Wi, max-width)*Hi/Wi)</li>
<li>(min(Hi, max-height)*Wi/Hi, min(Hi, max-height))</li>
<li>(max(Wi, min-width), min(Hi, max-height))</li>
<li>(min(Wi, max-width), max(Hi, min-height))</li>
<li>(max(Wi, min-width), max(Hi, min-height))</li>
<li>(min(Wi, max-width), min(Hi, max-height))</li>
</ol>
</li>
<li>Then apply the rules under <a
href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above, as if <span class="propinst-width">'width'</span>
were computed as this value.
</li>
</ol>
-->
<h2><a name="the-height-property">Content height</a>: the <span
class="propinst-height">'height'</span> property</h2>
<!-- #include src=properties/height.srb -->
<p> This property specifies the <a
href="box.html#content-height">content height</a> of boxes.
<p>This property does not apply to non-replaced <a
href="visuren.html#inline-boxes">inline</a> elements. See the <a
href="#inline-non-replaced">section on computing heights and margins
for non-replaced inline elements</a> for the rules used instead.
</p>
<p>Values have the following meanings:</p>
<dl>
<dt><span class="index-inst" title="<length>"><span class="value-inst-length"><strong><length></strong></span></span>
</dt>
<dd>Specifies the height of the content area using a length value.
</dd>
<dt><span class="index-inst" title="<percentage>"><span class="value-inst-percentage"><strong><percentage></strong></span></span>
</dt>
<dd>Specifies a percentage height. The percentage is calculated with
respect to the height of the generated box's <a
href="visuren.html#containing-block">containing block</a>. If the
height of the containing block is not specified explicitly (i.e., it
depends on content height), and this element is not absolutely
positioned, the used height is calculated as if 'auto' was specified.
A percentage height
on the <a href="conform.html#root">root element</a> is relative to the
<a href="#containing-block-details">initial containing block</a>.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block-level element, the percentage is calculated with
respect to the height of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><strong>auto</strong>
</dt>
<dd>The height depends on the values of other properties.
See the prose below.
</dd>
</dl>
<p class="note">Note that the height of the containing block of an
absolutely positioned element is independent of the size of the
element itself, and thus a percentage height on such an element can
always be resolved. However, it may be that the height is not known
until elements that come later in the document have been processed.
</p>
<p>Negative values for <span class="propinst-height">'height'</span>
are illegal.
</p>
<div class="example"><p>
For example, the following rule sets the content height of paragraphs
to 100 pixels:</p>
<pre>
p { height: 100px }
</pre>
<p>Paragraphs of which the height of the contents exceeds 100 pixels
will <a href="visufx.html#overflow">overflow</a> according to the
<span class="propinst-overflow">'overflow'</span> property.
</p>
</div>
<h2><a name="Computing_heights_and_margins">Calculating heights and
margins</a></h2>
<p>For calculating the values of <span class="propinst-top">'top'</span>, <span class="propinst-margin-top">'margin-top'</span>, <span class="propinst-height">'height'</span>,
<span class="propinst-margin-bottom">'margin-bottom'</span>, and <span class="propinst-bottom">'bottom'</span> a distinction must be made between
various kinds of boxes:
</p>
<ol>
<li>inline, non-replaced elements</li>
<li>inline, replaced elements</li>
<li>block-level, non-replaced elements in normal flow</li>
<li>block-level, replaced elements in normal flow</li>
<li>floating, non-replaced elements</li>
<li>floating, replaced elements</li>
<li>absolutely positioned, non-replaced elements</li>
<li>absolutely positioned, replaced elements</li>
<li>'inline-block', non-replaced elements in normal flow</li>
<li>'inline-block', replaced elements in normal flow</li>
</ol>
<p>For Points 1-6 and 9-10, the used values of 'top' and
'bottom' are determined by the rules in section 9.4.3.
</p>
<p class=note>Note: these rules apply to
the root element just as to any other element.
<p class=note><em><strong>Note.</strong> The used value of 'height'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on <span
class="propinst-min-height">'min-height'</span> and <span
class="propinst-max-height">'max-height'</span>, see the section <a
href="#min-max-heights">Minimum and maximum heights</a> below.</em>
<h3><a name="inline-non-replaced">Inline, non-replaced elements</a></h3>
<p>The <span class="propinst-height">'height'</span> property does not
apply. The height of the content area should be based on the font, but
this specification does not specify how. A UA may, e.g., use the
em-box or the maximum ascender and descender of the font. (The latter
would ensure that glyphs with parts above or below the em-box still
fall within the content area, but leads to differently sized boxes for
different fonts; the former would ensure authors can control
background styling relative to the 'line-height', but leads to glyphs
painting outside their content area.)
</p>
<p class=note>Note: level 3 of CSS will probably include a property to
select which measure of the font is used for the content height.
</p>
<p>The vertical padding, border and margin of an inline, non-replaced
box start at the top and bottom of the content area, and has nothing
to do with the <span
class="propinst-line-height">'line-height'</span>. But only the <span
class="propinst-line-height">'line-height'</span> is used when calculating
the height of the line box.
</p>
<p><a name="multi-font-inline-height"></a> If more than one font is
used (this could happen when glyphs are found in different fonts), the
height of the content area is not defined by this specification.
However, we suggest that the height is chosen such that the content
area is just high enough for either (1) the em-boxes, or (2) the
maximum ascenders and descenders, of <em>all</em> the fonts in the
element. Note that this may be larger than any of the font sizes
involved, depending on the baseline alignment of the fonts.
</p>
<h3><a name="inline-replaced-height">Inline replaced elements</a>,
block-level replaced elements in normal flow, 'inline-block' replaced
elements in normal flow and floating replaced elements</h3>
<p>If <span class="propinst-margin-top">'margin-top'</span>, or <span
class="propinst-margin-bottom">'margin-bottom'</span> are 'auto',
their used value is 0.
<p>If <span class="propinst-height">'height'</span> and <span
class="propinst-width">'width'</span> both have computed values of
'auto' and the element also has an intrinsic height, then that
intrinsic height is the used value of <span
class="propinst-height">'height'</span>.
<p>Otherwise, if <span class="propinst-height">'height'</span> has a
computed value of 'auto', and the element has an intrinsic ratio then
the used value of <span class="propinst-height">'height'</span> is:
<blockquote><p>(used width) / (intrinsic ratio)</blockquote>
<p>Otherwise, if <span class="propinst-height">'height'</span> has a
computed value of 'auto', and the element has an intrinsic height,
then that intrinsic height is the used value of <span
class="propinst-height">'height'</span>.
<p>Otherwise, if <span class="propinst-height">'height'</span> has a
computed value of 'auto', but none of the conditions above are met,
then the used value of <span class="propinst-height">'height'</span>
must be set to the height of the largest rectangle that has a 2:1
ratio, has a height not greater than 150px, and has a width not
greater than the device width.
<!-- Issue 181: remove the following -->
<!-- <p>For 'inline' and 'inline-block' elements, the margin box is used
when calculating the height of the line box. -->
<!-- /Issue 181 -->
<h3><a name="normal-block">Block-level non-replaced elements in normal
flow when 'overflow' computes to 'visible'</a></h3>
<p>This section also applies to block-level non-replaced elements in
normal flow when 'overflow' does not compute to 'visible' but has been
propagated to the viewport.
<p>If <span
class="propinst-margin-top">'margin-top'</span>, or <span
class="propinst-margin-bottom">'margin-bottom'</span> are 'auto',
their used value is 0. If <span
class="propinst-height">'height'</span> is 'auto', the height depends
on whether the element has any block-level children and whether it has
padding or borders:
</p>
<p>The element's height is the distance from its top content edge to
the first applicable of the following:
<ol>
<li>the bottom edge of the last line box, if the box establishes a
inline formatting context with one or more lines
<li>the bottom edge of the bottom (possibly collapsed) margin of its
last in-flow child, if the child's bottom margin does not collapse
with the element's bottom margin
<li>the bottom border edge of the last in-flow child whose top
margin doesn't collapse with the element's bottom margin
<li>zero, otherwise
</ol>
<p>Only children in the normal flow are taken into account (i.e.,
floating boxes and absolutely positioned boxes are ignored, and
relatively positioned boxes are considered without their offset). Note
that the child box may be an <a
href="visuren.html#anonymous-block-level">anonymous block box.</a>