forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.src
More file actions
686 lines (555 loc) · 23.2 KB
/
Copy pathbox.src
File metadata and controls
686 lines (555 loc) · 23.2 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en">
<!-- $Id: box.src,v 1.2 1997-10-30 08:27:57 ian Exp $ -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>Box rendering type</TITLE>
<LINK rel="next" href="flowobj.html">
<LINK rel="previous" href="media.html">
<LINK rel="STYLESHEET" href="style/default.css" type="text/css">
</HEAD>
<BODY>
<H1 align="center">Box rendering type</H1>
<H2><a name="box-model">Introduction to the box rendering type</a></H2>
<P>The CSS box model describes the box <a
href="process.html#renderobj">rendering object</a> type. This type is
characterized in particular by three groups of properties: <a
href="#margin-properties">margin</a>, <a
href="#padding-properties">padding</a>, and <a
href="#border-properties">border</a>, described below.
<P>For information on the <em>layout</em> of boxes, please consult the
section on the <a href="flowobj.html">visual flow model</a>.
<P>The box model is slightly different for the case of <a
href="paged.html">paged media.</a> Please consult the section on <a
href="paged.html#page-boxes">page boxes</a> for more information.
<H3><a name="box-dimensions">Box dimensions</a></H3>
<P>Each box has a core content area (e.g., text, an image, etc.) and
optional surrounding padding, border and margin areas. The following
diagram illustrates how these areas relate and defines more precise
terminology used to describe pieces of margin, border, and
padding:</P>
<img src="./images/boxdim.gif"
alt="Image illustrating the relationship between content, padding, borders, and margins.">
<P>The width (resp., height) of the box is given by the sum of the
content width (resp., height), the padding, the border, and the margin.
The size of the margin, border and padding are set with the <a
href="#margin-properties">margin</a>, <a
href="#padding-properties">padding</a>, and <a
href="#border-properties">border</a> properties, respectively.
<P> The <EM>left outer edge</EM> is the edge of an element with its
padding, border, and margin taken into account. The <EM>left inner
edge</EM> is the edge of the content only, inside any padding, border
or margin. The same holds for the <em>right inner edge</em>.
<P>The <EM>top</EM> is the top of the object including any padding,
border and margin; it is only defined for <a
href="flowobj.html#inline">inline</a> and floating elements, not for
non-floating block-level elements. The <EM>inner top</EM> is the top
of the content, inside any padding, border or margin. The
<EM>bottom</EM> is the bottom of the element, outside any padding
border and margin; it is only defined for inline and <a
href="flowobj.html#floats">floating elements</a>, not for non-floating
<a href="block-level">block-level</a> elements. The <EM>inner
bottom</EM> is the bottom of the element, inside any padding, border
and margin.
<P> The <EM>width</EM> of an element is the width of the content,
i.e., the distance between left inner edge and right inner edge. The
<EM>height</EM> is the height of the content, i.e., the distance from
inner top to inner bottom.
<P>In the following sections, we define the properties that allow
authors to set margins, padding, and borders.
<div class="note"><P>
<em><strong>Note.</strong>
The properties that specify the foreground and background colors of
an element's content and padding area are described in the section on
<a href="colors.html">colors and backgrounds</a>. Border colors and
styles are set with the <a href="#border-properties">border
properties</a>. Margins are always transparent so the background
of the parent element always shines through.
</em>
</div>
<H3><a name="margin-properties">Margin properties</a>:
<span class="propinst-margin-top">'margin-top'</span>,
<span class="propinst-margin-right">'margin-right'</span>,
<span class="propinst-margin-bottom">'margin-bottom'</span>,
<span class="propinst-margin-left">'margin-left'</span>, and
<span class="propinst-margin">'margin'</span></H3>
<P>Margin properties set the margin of an element. The
<span class="propinst-margin">'margin'</span> property sets the border
for all four sides while the other margin properties only set their
respective side.
<H4><a name="border-width-defs">Values for </a><span class="index-def"
title="<margin-width>, definition of"><a
name="value-def-margin-width"><margin-width></a></span></H4>
<P>The properties defined in this section refer to the
<span class="value-inst-margin-width"><margin-width></span>
value type, whose possible values may be:
<P><span class="value-inst-length"><length></span> |
<span class="value-inst-percentage"><percentage></span> |
auto</P>
<P>Negative values for margin properties are allowed, but there may be
implementation-specific limits.
<P>Percentage values for margin properties refer to the width of
the containing block.
<!-- #include src=properties/margin-top.srb -->
<P>This property sets the top margin of an element. It applies to
replaced and block-level elements.
<div class="example"><P>
<PRE>
H1 { margin-top: 2em }
</PRE>
</div>
<!-- #include src=properties/margin-right.srb -->
<P>This property sets the right margin of an element:
<div class="example"><p>
<PRE>
H1 { margin-right: 12.3% }
</PRE>
</div>
<!-- #include src=properties/margin-bottom.srb -->
<P> This property sets the bottom margin of an element. It applies to
replaced and block-level elements.
<div class="example"><P>
<PRE>
H1 { margin-bottom: 3px }
</PRE>
</div>
<!-- #include src=properties/margin-left.srb -->
<P> This property sets the left margin of an element:
<div class="example"><P>
<PRE>
H1 { margin-left: 2em }
</PRE>
</div>
<!-- #include src=properties/margin.srb -->
<P> The <span class="propinst-margin">'margin'</span> property is a shorthand
property for setting <span class="propinst-margin-top">'margin-top'</span>, <span
class="propinst-margin-right">'margin-right'</span> <span
class="propinst-margin-bottom">'margin-bottom'</span> and <span
class="propinst-margin-left">'margin-left'</span> at the same place in the style
sheet.
<P> If four length values are specified they apply to top, right,
bottom and left respectively. If there is only one value, it applies
to all sides, if there are two or three, the missing values are taken
from the opposite side.
<div class="example"><P>
<PRE>
BODY { margin: 2em } /* all margins set to 2em */
BODY { margin: 1em 2em } /* top & bottom = 1em, right & left = 2em */
BODY { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */
</PRE>
<P> The last rule of the example above is equivalent to the example
below:
<PRE>
BODY {
margin-top: 1em;
margin-right: 2em;
margin-bottom: 3em;
margin-left: 2em; /* copied from opposite side (right) */
}
</PRE>
</div>
<H3><a name="padding-properties">Padding properties</a>:
<span class="propinst-padding-top">'padding-top'</span>,
<span class="propinst-padding-right">'padding-right'</span>,
<span class="propinst-padding-bottom">'padding-bottom'</span>,
<span class="propinst-padding-left">'padding-left'</span>, and
<span class="propinst-padding">'padding'</span>
</H3>
<P> The
padding properties describe how much space to insert between the
border and the content (e.g., text or image). The <span
class="propinst-padding">'padding'</span> property sets the padding
for all four sides while the other padding properties only set their
respective side.
<H4><a name="border-width-defs">Values for </a><span class="index-def"
title="<padding-width>, definition of"><a
name="value-def-padding-width"><padding-width></a></span></H4>
<P>The properties defined in this section refer to the
<span class="value-inst-padding-width"><padding-width></span>
value type, whose possible values may be:
<P><span class="value-inst-length"><length></span> |
<span class="value-inst-percentage"><percentage></span></P>
<P>Unlike margin properties, values for padding values cannot be
negative.
<P>Like margin properties, percentage values for padding properties
refer to the width of the containing block.
<!-- #include src=properties/padding-top.srb -->
<P> This property sets the top padding of an element.
<div class="example"><P>
<PRE>
BLOCKQUOTE { padding-top: 0.3em }
</PRE>
</div>
<!-- #include src=properties/padding-right.srb -->
<P> This property sets the right padding of an element.
<div class="example"><P>
<PRE>
BLOCKQUOTE { padding-right: 10px }
</PRE>
</div>
<!-- #include src=properties/padding-bottom.srb -->
<P> This property sets the bottom padding of an element.
<div class="example"><P>
<PRE>
BLOCKQUOTE { padding-bottom: 2em }
</PRE>
</div>
<!-- #include src=properties/padding-left.srb -->
<P> This property sets the left padding of an element.
<div class="example"><P>
<PRE>
BLOCKQUOTE { padding-left: 20% }
</PRE>
</div>
<!-- #include src=properties/padding.srb -->
<P> The <span class="propinst-padding">'padding'</span> property is a
shorthand property for setting <span
class="propinst-padding-top">'padding-top'</span>, <span
class="propinst-padding-right">'padding-right'</span>, <span
class="propinst-padding-bottom">'padding-bottom'</span>, and <span
class="propinst-padding-left">'padding-left'</span> at the same place in the style
sheet.
<P> If four values are specified they apply to top, right, bottom and
left respectively. If there is only one value, it applies to all
sides, if there are two or three, the missing values are taken from
the opposite side.
<P> The surface of the padding area is set with the <span
class="propinst-background">'background'</span> property:
<div class="example"><P>
<PRE>
H1 {
background: white;
padding: 1em 2em;
}
</PRE>
<P> The example above sets a '1em' padding vertically (<span
class="propinst-padding-top">'padding-top'</span> and <span
class="propinst-padding-bottom">'padding-bottom'</span>) and a '2em'
padding horizontally (<span
class="propinst-padding-right">'padding-right'</span> and <span
class="propinst-padding-left">'padding-left'</span>). The 'em' unit is
relative to the element's font size: '1em' is equal to the size of the
font in use.
</div>
<H3><a name="border-properties">Border properties</a>: <span
class="propinst-border-top-width">'border-top-width'</span>, <span
class="propinst-border-right-width">'border-right-width'</span>, <span
class="propinst-border-bottom-width">'border-bottom-width'</span>,
<span class="propinst-border-left-width">'border-left-width'</span>,
<span class="propinst-border-width">'border-width'</span>,
<span class="propinst-border-color">'border-color'</span>,
<span class="propinst-border-style">'border-style'</span>,
<span class="propinst-border-top">'border-top'</span>,
<span class="propinst-border-bottom">'border-bottom'</span>,
<span class="propinst-border-right">'border-right'</span>,
<span class="propinst-border-left">'border-left'</span>, and
<span class="propinst-border">'border'</span>
</H3>
<P>The border properties set the borders of an element. Each element
has four borders, one on each side, that are defined by their width,
color and style.
<H4><a name="border-width-defs">Values for </a><span class="index-def"
title="<border-width>, definition of"><a
name="value-def-border-width"
class="value-def"><border-width></a></span></H4>
<P>The properties defined in this section refer to the
<span class="value-inst-border-width"><border-width></span>
value type, whose possible values may be:
<ul>
<li> 'thin' | 'medium' | 'thick' |
<span class="value-inst-length"><length></span></li>
</ul>
<P>The interpretation of the first three values depends on the user agent. The following must hold, however:
<P>'thin' <='medium' <= 'thick'.
<P>Furthermore, these widths must be constant throughout a document.
<P> Border widths cannot be negative.
<!-- #include src=properties/border-top-width.srb -->
<P> This property sets the width of an element's top border.
<div class="example"><P>
<PRE>
H1 { border: solid thick red }
P { border: solid thick blue }
</PRE>
<P> In the example above, H1 and P elements will have the same
border width regardless of font size. To achieve relative widths, the
'em' unit can be used:
<PRE>
H1 { border: solid 0.5em }
</PRE>
</div>
<!-- #include src=properties/border-right-width.srb -->
<P> This property sets the width of an element's right
border.
<!-- #include src=properties/border-bottom-width.srb -->
<P> This property sets the width of an element's bottom border.
<!-- #include src=properties/border-left-width.srb -->
<P> This property sets the width of an element's left border.
<!-- #include src=properties/border-width.srb -->
<P> This property is a shorthand property for setting
<span class="propinst-border-top-width">'border-top-width'</span>,
<span class="propinst-border-right-width">'border-right-width'</span>,
<span class="propinst-border-bottom-width">'border-bottom-width'</span>,
and
<span class="propinst-border-width-left">'border-left-width'</span> at
the same place in the style sheet.
<P> There can be from one to four values, with the following
interpretation:
<UL>
<LI>
one value: all four border widths are set to that value
<LI>
two values: top and bottom border widths are set to the first
value, right and left are set to the second
<LI>
three values: top is set to the first, right and left are set to
the second, bottom is set to the third
<LI>
four values: top, right, bottom and left, respectively
</UL>
<div class="example"><P>
In the examples below, the comments indicate the resulting widths
of the top, right, bottom and left borders:
<PRE>
H1 { border-width: thin } /* thin thin thin thin */
H1 { border-width: thin thick } /* thin thick thin thick */
H1 { border-width: thin thick medium } /* thin thick medium thick */
</PRE>
</div>
<!-- #include src=properties/border-color.srb -->
<P> The <span class="propinst-border-color">'border-color'</span>
property sets the color of the four borders. <span
class="propinst-border-color">'border-color'</span> can have from one
to four values, and the values are set on the different sides as for
<span class="propinst-border-width">'border-width'</span> above.
<P> If no color value is specified, the value of the <span
class="propinst-color">'color'</span> property of the element itself
will take its place:
<div class="example"><P>
<PRE>
P {
color: black;
background: white;
border: solid;
}
</PRE>
<P> In the above example, the border will be a solid black line.
</div>
<!-- #include src=properties/border-style.srb -->
<P> The <span class="propinst-border-style">'border-style'</span> property sets the style of the
four borders. It can have from one to four values, and the values are
set on the different sides as for <span class="propinst-border-width">'border-width'</span> above.
<div class="example"><P>
<PRE>
#xy34 { border-style: solid dotted }
</PRE>
<P> In the above example, the horizontal borders will be 'solid' and
the vertical borders will be 'dotted'.
</div>
<P> Since the initial value of the border styles is 'none', no borders
will be visible unless the border style is set.
<P>
The border styles mean:
<DL>
<DT>
none
<DD>
no border is drawn (regardless of the <span
class="propinst-border-width">'border-width'</span> property's value)
<DT>
dotted
<DD>
the border is a dotted line drawn on top of the background of the element
<DT>
dashed
<DD>
the border is a dashed line drawn on top of the background of the element
<DT>
solid
<DD>
the border is a solid line
<DT>
double
<DD>
the border is a double line drawn on top of the background of the element.
The sum of the two single lines and the space between equals the
value of <span class="propinst-border-width">'border-width'</span>.
<DT>
groove
<DD>
a 3D groove is drawn in colors based on the value of the <span
class="propinst-color">'color'</span> property.
<DT>
ridge
<DD>
a 3D ridge is drawn in colors based on the value of the <span
class="propinst-color">'color'</span> property.
<DT>
inset
<DD>
a 3D inset is drawn in colors based on the value of the <span
class="propinst-color">'color'</span> property.
<DT>
outset
<DD>
a 3D outset is drawn in colors based on the value of the <span
class="propinst-color">'color'</span> property.
</DL>
<P>UAs may interpret all of 'dotted', 'dashed', 'double',
'groove', 'ridge', 'inset' and 'outset' as 'solid'. See the section on <a
href="convent.html#conformance">conformance</a> for details.
<!-- #include src=properties/border-top.srb -->
<P> This is a shorthand property for setting the width, style and
color of an element's top border.
<div class="example"><P>
<PRE>
H1 { border-bottom: thick solid red }
</PRE>
<P> The above rule will set the width, style and color of the border
<strong>below</strong> the H1 element. Omitted values will be set to
their initial values:
<PRE>
H1 { border-bottom: thick solid }
</PRE>
<P> Since the color value is omitted in the example above, the border
color will be the same as the 'color' value of the element itself.
</div>
<P> Note that while the <span
class="propinst-border-style">'border-style'</span> property accepts
up to four values, this property only accepts one style value.
<!-- #include src=properties/border-bottom.srb -->
<P> This is a shorthand property for setting the width, style and
color of an element's bottom border. It behaves just like <span
class="propinst-border-top">'border-top'</span>.
<!-- #include src=properties/border-right.srb -->
<P> This is a shorthand property for setting the width, style and
color of an element's right border. It behaves just like <span
class="propinst-border-top">'border-top'</span>.
<!-- #include src=properties/border-left.srb -->
<P> This is a shorthand property for setting the width, style and
color of an element's left border. It behaves just like <span
class="propinst-border-top">'border-top'</span>.
<!-- #include src=properties/border.srb -->
<P> The <span class="propinst-border">'border'</span>
property is a shorthand property for setting the same width, color and
style on all four borders of an element.
<P> Unlike the shorthand <span class="propinst-margin">'margin'</span> and <span class="propinst-padding">'padding'</span> properties, the <span
class="propinst-border">'border'</span> property cannot
set different values on the four borders. To do so, one or more of the
other border properties must be used.
<P> Note that while the <span class="propinst-border-width">'border-width'</span> property accepts up to four
length values, this property only accepts one.
<div class="example"><P>
For example, the first rule below is
equivalent to the set of four rules shown after it:
<PRE>
P { border: solid red }
P {
border-top: solid red;
border-right: solid red;
border-bottom: solid red;
border-left: solid red
}
</PRE>
</div>
<P> Since to some extent the properties have overlapping
functionality, the order in which the rules are specified becomes
important.
<div class="example"><P>
Consider this example:
<PRE>
BLOCKQUOTE {
border-color: red;
border-left: double
color: black;
}
</PRE>
<P> In the above example, the color of the left border will be black,
while the other borders are red. This is due to <span
class="propinst-border-left">'border-left'</span>> setting the
width, style and color. Since the color value is not given by the
<span class="propinst-border-left">'border-left'</span> property, it
will be taken from the <span class="propinst-color">'color'</span>
property. The fact that the <span
class="propinst-color">'color'</span> property is set after the <span
class="propinst-border-left">'border-left'</span> property is not
relevant.
</div>
<H3><a name="mpb-examples">Example of margins, padding, and borders</a></H3>
This example illustrates how margins, padding, and borders
interact. The example HTML document:
<PRE>
<STYLE type="text/css">
UL {
background: orange;
margin: 12px 12px 12px 12px
padding: 3px 3px 3px 3px
/* No borders by default. */
}
LI {
color: white; /* text color is white */
background: blue; /* Content, padding will be blue */
margin: 12px 12px 12px 12px
padding: 12px 0px 12px 12px /* Note 0px padding right */
list-style: none /* no glyphs before a list item */
/* No borders by default. */
}
LI.withborder {
border-style: dashed;
border-width: medium; /* sets border width on all sides */
border-color: green;
}
</STYLE>
<UL>
<LI>First element of list
<LI class="withborder">Second element of list is longer
to illustrate wrapping.
</UL>
</PRE>
<P>results in a <a href="process.html#doctree">document
tree</a> with (among other relationships) a UL element that
has two LI children. According to the <a href="flowobj.html#flow-model">
visual rendering model</a>, the LI elements are
laid out vertically (one after the other) and form the
content of the UL.
<P>The first of the following diagrams illustrates what this example
would produce. The second illustrates the relationship between the
margins, padding, and borders of the UL elements and those of its
children LI elements.</P>
<img src="./images/boxdimeg.gif"
alt="Image illustrating how parent and child margins, borders,
and padding relate.">
<P>Note that:</p>
<ul>
<li>The width of content for each LI element has not been specified by
the <span class="propinst-width">'width'</span> property. Therefore,
according to the rules of the <a href="flowobj2.html#box-height">box
height calculations</a>, the width allotted for the content of each LI
element is the width of the parent element's (UL) content less the
margins, padding, and border of the LI elements. The width of the UL
element is determined by the width of its parent, not shown explicitly
here.
<li>The height of each LI element's contents is determined by the
height of the content. The height of the UL element's content is
determined by the sum of the heights of the LI elements' content, plus
LI margins, padding, and borders (see the section on <a
href="flowobj2.html#box-height">box height calculations</a> for
details). Note that <a
href="flowobj2.html#collapsing-margins">vertical margins between the
LI boxes collapse.</a>
<li>By default, borders have zero width. The only non-zero border in
this example is the green, medium dashed line surrounding the second
list item's padding.
<li>The right side padding of the LI elements has been set to zero
width. The effect is apparent in the second illustration.
<li>The foreground color of the LI elements has been set
to white for legibility against a blue background.
<li>The margins and padding of the LI elements are transparent (by
default), so the background color of the UL elements (orange) shines
through the transparent LI margins. However, the (blue) background
color (blue) of the LI elements changes the color of the LI padding
and content.
<li>Although padding and margin properties are not inherited, the LI
elements are still offset by the UL margin.
</ul>
</body>
</html>