-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathbox.src
836 lines (695 loc) · 32.7 KB
/
box.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
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'>
<html lang="en">
<!-- $Id: box.src,v 1.89 2012-05-15 14:12:14 bbos Exp $ -->
<HEAD>
<TITLE>Box model</TITLE>
<!--script src="http://www.w3c-test.org/css/harness/annotate.js#CSS21_DEV" type="text/javascript" defer></script-->
</HEAD>
<BODY>
<H1><a name="box-model">Box model</a></H1>
<P>The CSS box model describes the rectangular boxes that are
generated for elements in the <a href="conform.html#doctree">document
tree</a> and laid out according to the <a href="visuren.html">visual formatting
model</a>.
<H2><a name="box-dimensions">Box dimensions</a></H2>
<P>Each box has a
<span class="index-def" title="box::content|content::of a box">
<a name="box-content-area"><dfn>content area</dfn></a></span> (e.g.,
text, an image, etc.) and optional surrounding
<span class="index-def" title="box::padding|padding::of a box">
<a name="box-padding-area"><dfn>padding</dfn></a></span>,
<span class="index-def" title="box::border|border::of a box">
<a name="box-border-area"><dfn>border</dfn></a></span>, and
<span class="index-def" title="box::margin|margin::of a box">
<a name="box-margin-area"><dfn>margin</dfn></a></span> areas; the size
of each area is specified by properties defined below. The following
diagram shows how these areas relate and the terminology used to refer
to pieces of margin, border, and padding:</P>
<div class="figure">
<P><img src="./images/boxdim.png"
alt="Image illustrating the relationship between content, padding, borders, and margins."></P>
</div>
<P>The margin, border, and padding can be broken down into top, right,
bottom, and left segments (e.g., in the diagram, "LM" for left margin,
"RP" for right padding, "TB" for top border, etc.).
<P>The perimeter of each of the four areas (content, padding, border,
and margin) is called an "edge", so each box has four edges:</P>
<dl>
<dt><span class="index-def"
title="content edge"><a name="content-edge"><strong>content edge</strong></a></span>
or <span class="index-def" title="inner edge"><a name="inner-edge"><strong>inner edge</strong></a></span>
<dd>The content edge surrounds the rectangle given by the <a
href="visudet.html#Computing_widths_and_margins">width</a> and <a
href="visudet.html#Computing_heights_and_margins">height</a>
of the box, which often depend on the element's <a
href="conform.html#rendered-content">rendered content</a>.
The four content edges define the
box's <dfn><span class="index-def">content box</span></dfn>.
<dt><span class="index-def" title="padding edge"><a name="padding-edge"><strong>padding edge</strong></a></span>
<dd>The padding edge surrounds the box padding. If the padding
has 0 width, the padding edge is the same as the content edge.
The four padding edges define the
box's <dfn><span class="index-def">padding box</span></dfn>.
<dt><span class="index-def" title="border edge"><a name="border-edge"><strong>border edge</strong></a></span>
<dd>The border edge surrounds the box's border. If the border
has 0 width, the border edge is the same as the padding edge.
The four border edges define the box's <dfn><span class="index-def">border
box</span></dfn>.
<dt><span class="index-def" title="margin edge"><a name="margin-edge"><strong>margin edge</strong></a></span>
or <span class="index-def" title="outer edge"><a name="outer-edge"><strong>outer
edge</strong></a></span>
<dd>The margin edge surrounds the box margin. If the margin
has 0 width, the margin edge is the same as the border edge.
The four margin edges define the box's <dfn><span class="index-def">margin
box</span></dfn>.
</dl>
<P>Each edge may be broken down into a top, right, bottom, and left
edge.
<P>The dimensions of the content area of a box — the <span
class="index-def" title="box::content width"><a
name="content-width"><dfn>content width</dfn></a></span> and <span
class="index-def" title="box::content height"><a
name="content-height"><dfn>content height</dfn></a></span> —
depend on several factors: whether the element generating
the box has the <span class="propinst-width">'width'</span>
or <span class="propinst-height">'height'</span> property
set, whether the box contains text or other boxes, whether the
box is a table, etc. Box widths and heights are discussed
in the chapter on <a href="visudet.html">visual formatting
model details</a>.
<P>The background style of the content, padding, and border areas of a
box is specified by the <span
class="propinst-background">'background'</span> property of the
generating element. Margin backgrounds are always transparent.
<H2><a name="mpb-examples">Example of margins, padding, and borders</a></H2>
<P>This example illustrates how margins, padding, and borders
interact. The example HTML document:
<pre class="html-example">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<TITLE>Examples of margins, padding, and borders</TITLE>
<STYLE type="text/css">
UL {
background: yellow;
margin: 12px 12px 12px 12px;
padding: 3px 3px 3px 3px;
/* No borders set */
}
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 set */
}
LI.withborder {
border-style: dashed;
border-width: medium; /* sets border width on all sides */
border-color: lime;
}
</STYLE>
</HEAD>
<BODY>
<UL>
<LI>First element of list
<LI class="withborder">Second element of list is
a bit longer to illustrate wrapping.
</UL>
</BODY>
</HTML>
</pre>
<P>results in a <a href="conform.html#doctree">document tree</a> with
(among other relationships) a UL element that has two LI
children.
<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. (Image is not to scale.)</P>
<div class="figure">
<P><img src="./images/boxdimeg.png"
alt="Image illustrating how parent and child margins, borders,
and padding relate."></p>
</div>
<P>Note that:</p>
<ul>
<li>The <a href="#content-width">content width</a> for each LI box is
calculated top-down; the <a href="visuren.html#containing-block">containing
block</a> for each LI box is established by the UL element.
<li>The margin box height of each LI box depends on its <a
href="#content-height">content height</a>, plus top and bottom
padding, borders, and margins. Note that vertical margins between the
LI boxes <a href="#collapsing-margins">collapse.</a>
<li>The right padding of the LI boxes has been set to zero width
(the <span class="propinst-padding">'padding'</span> property). The
effect is apparent in the second illustration.
<li>The margins of the LI boxes are transparent — margins are always
transparent — so the background color (yellow) of the UL padding and
content areas shines through them.
<li>The second LI element specifies a dashed border (the
<span class="propinst-border-style">'border-style'</span> property).
</ul>
<H2><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></H2>
<P>Margin properties specify the width of the <a
href="#box-margin-area">margin area</a> of a box. The <span
class="propinst-margin">'margin'</span> shorthand property sets the
margin for all four sides while the other margin properties only set
their respective side. These properties apply to all elements, but
vertical margins will not have any effect on non-replaced inline
elements.
<P>The properties defined in this section refer to the <span
class="index-def" title="<margin-width>::definition of"><a
name="value-def-margin-width"><strong><margin-width></strong></a></span>
value type, which may take one of the following values:</p>
<dl>
<dt><span class="value-inst-length"><strong><length></strong></span>
<dd>Specifies a fixed width.
<dt><span class="value-inst-percentage"><strong><percentage></strong></span>
<dd>The percentage is calculated
with respect to the <em>width</em> of the generated box's
<a href="visuren.html#containing-block">containing block</a>.
<span class="note">Note that this is true for <span
class="propinst-margin-top">'margin-top'</span> and <span
class="propinst-margin-bottom">'margin-bottom'</span> as well.</span>
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS 2.2.
<dt><strong>auto</strong>
<dd>See the section on <a
href="visudet.html#Computing_widths_and_margins">calculating widths and
margins</a> for behavior.
</dl>
<P>Negative values for margin properties are allowed, but there may be
implementation-specific limits.
<!-- #include src=properties/margin-top.srb -->
<p class="note">These properties have no effect on non-replaced inline
elements.</p>
<!-- #include src=properties/margin-right.srb -->
<P>These properties set the top, right, bottom, and left margin of a
box.
<div class="example"><P>
<PRE>
h1 { margin-top: 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 there is only one component value, it applies to all
sides. If there are two values, the top and bottom margins
are set to the first value and the right and left margins are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<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="collapsing-margins">Collapsing margins</a></H3>
<P>In CSS, the adjoining margins of two or more boxes (which might or
might not be siblings) can combine to form a single margin. Margins
that combine this way are said to <dfn><span
class="index-def">collapse</span></dfn>, and the
resulting combined margin is called a <dfn><span class="index-def"
title="collapsing margin">collapsed margin</span></dfn>.
<P>Adjoining vertical margins collapse, except:
<UL>
<LI>Margins of the root element's box do not collapse.
<LI>If the top and bottom margins of an element with <a
href="visuren.html#clearance">clearance</a> are adjoining, its
margins collapse with the adjoining margins of following siblings
but that resulting margin does not collapse with the bottom margin
of the parent block.
<LI>If the top margin of a box with non-zero computed
'min-height' and 'auto' computed 'height' collapses with the
bottom margin of its last in-flow child, then the child's bottom
margin does not collapse with the parent's bottom margin.
</UL>
<P>Horizontal margins never collapse.
<P ID="what-is-adjoining">Two margins are <span class="index-def"
title="adjoining margins"><DFN>adjoining</DFN></span> if and only if:
<UL>
<LI>both belong to in-flow <a
href="visuren.html#block-boxes">block-level boxes</a> that
participate in the same <a
href="visuren.html#block-formatting">block formatting context</a>
<LI>no line boxes, no clearance, no padding and no border separate
them <span class="note">(Note that <a
href="visuren.html#phantom-line-box">certain zero-height line
boxes</a> (see <a href="visuren.html#inline-formatting">9.4.2</a>)
are ignored for this purpose.)</span>
<LI>both belong to vertically-adjacent box edges, i.e. form one of
the following pairs:
<UL>
<LI>top margin of a box and top margin of its first in-flow child
<LI>bottom margin of box and top margin of its next in-flow
following sibling
<LI>bottom margin of a last in-flow child and bottom margin of its
parent if the parent has 'auto' computed height
<LI>top and bottom margins of a box that does not establish a new
block formatting context and that has zero computed <span
class="propinst-min-height">'min-height'</span>, zero or 'auto'
computed <span class="propinst-height">'height'</span>, and no
in-flow children
</UL>
</UL>
<P>A collapsed margin is considered adjoining to another margin if any
of its component margins is adjoining to that margin.
<P CLASS=note><STRONG>Note.</STRONG> Adjoining margins can be
generated by elements that are not related as siblings or ancestors.
<DIV CLASS=note>
<P><STRONG>Note</STRONG> the above rules imply that:
<UL>
<LI>Margins between a <a href="visuren.html#floats">floated</a> box
and any other box do not collapse (not even between a float and its
in-flow children).
<LI>Margins of elements that establish new block formatting contexts
(such as floats and elements with <span
class="propinst-overflow">'overflow'</span> other than 'visible') do
not collapse with their in-flow children.
<LI>Margins of <a
href="visuren.html#absolutely-positioned">absolutely positioned</a>
boxes do not collapse (not even with their in-flow children).
<LI>Margins of inline-block boxes do not collapse (not even with
their in-flow children).
<LI>The bottom margin of an in-flow block-level element always
collapses with the top margin of its next in-flow block-level
sibling, unless that sibling has clearance.
<LI>The top margin of an in-flow block element collapses with its
first in-flow block-level child's top margin if the element has no
top border, no top padding, and the child has no clearance.
<LI>The bottom margin of an in-flow block box with a 'height' of
'auto' collapses with its last in-flow block-level child's bottom
margin, if:
<UL>
<LI>the box has no bottom padding, and
<LI>the box has no bottom border, and
<LI>the child's bottom margin neither collapses with a top margin
that has clearance, nor (if the box's min-height is non-zero)
with the box's top margin.
</UL>
<LI>A box's own margins collapse if the <span
class="propinst-min-height">'min-height'</span> property is zero,
and it has neither top or bottom borders nor top or bottom padding,
and it has a <span class="propinst-height">'height'</span> of either
0 or 'auto', and it does not contain a line box, and all of its
in-flow children's margins (if any) collapse.
</UL>
</DIV>
<P>When two or more margins collapse, the resulting margin width is
the maximum of the collapsing margins' widths. In the case of negative
margins, the maximum of the absolute values of the negative adjoining
margins is deducted from the maximum of the positive adjoining
margins. If there are no positive margins, the maximum of the
absolute values of the adjoining margins is deducted from zero.
<P ID="collapsed-through">If the top and bottom margins of a box are
adjoining, then it is possible for margins to <DFN><span
class="index-def">collapse through</span></DFN> it. In this case,
the position of the element depends on its relationship with the other
elements whose margins are being collapsed.
<UL>
<LI>If the element's margins are collapsed with its parent's top
margin, the top border edge of the box is defined to be the same as
the parent's.
<LI>Otherwise, either the element's parent is not taking part in the
margin collapsing, or only the parent's bottom margin is
involved. The position of the element's top border edge is the same
as it would have been if the element had a non-zero bottom border.
</UL>
<P>Note that the positions of elements that have been collapsed
through have no effect on the positions of the other elements with
whose margins they are being collapsed; the top border edge position
is only required for laying out descendants of these elements.
<H2><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>
</H2>
<P>The padding properties specify the width of the <a
href="#box-padding-area">padding area</a> of a box. The <span
class="propinst-padding">'padding'</span> shorthand property sets the
padding for all four sides while the other padding properties only set
their respective side.
<P>The properties defined in this section refer to the <span
class="index-def" title="<padding-width>::definition of"><a
name="value-def-padding-width"><strong><padding-width></strong>
</a></span> value type, which may take one of the following values:</p>
<dl>
<dt><span class="value-inst-length"><strong><length></strong></span>
<dd>Specifies a fixed width.
<dt><span class="value-inst-percentage"><strong><percentage></strong></span>
<dd>The percentage is calculated with
respect to the <em>width</em> of the generated box's <a
href="visuren.html#containing-block">containing block</a>, even for
<span class="propinst-padding-top">'padding-top'</span> and <span
class="propinst-padding-bottom">'padding-bottom'</span>.
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS 2.2.
</dl>
<P>Unlike margin properties, values for padding values cannot be
negative. Like margin properties, percentage values for padding
properties refer to the width of the generated box's containing block.
<!-- #include src=properties/padding-top.srb -->
<P>These properties set the top, right, bottom, and left padding of
a box.
<div class="example"><P>
<PRE>
blockquote { padding-top: 0.3em }
</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 there is only one component value, it applies to all
sides. If there are two values, the top and bottom paddings
are set to the first value and the right and left paddings are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<P> The surface color or image of the padding area is specified via
the <span class="propinst-background">'background'</span> property:
<div class="example"><P>
<PRE>
h1 {
background: white;
padding: 1em 2em;
}
</PRE>
<P> The example above specifies a '1em' vertical padding (<span
class="propinst-padding-top">'padding-top'</span> and <span
class="propinst-padding-bottom">'padding-bottom'</span>) and a '2em'
horizontal padding (<span
class="propinst-padding-right">'padding-right'</span> and <span
class="propinst-padding-left">'padding-left'</span>). The 'em' unit is
<a href="syndata.html#absrel-units">relative</a>
to the element's font size: '1em' is equal to the size of the
font in use.
</div>
<H2><a name="border-properties">Border properties</a></H2>
<P>The border properties specify the width, color, and style of the <a
href="#box-border-area">border area</a> of a box. These properties
apply to all elements.
<div class="note"><P>
<em><strong>Note.</strong>
Notably for HTML,
user agents may render borders for certain user interface elements (e.g.,
buttons, menus, etc.) differently than for
"ordinary" elements.
</em>
</div>
<H3><a name="border-width-properties">Border width</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>, and
<span class="propinst-border-width">'border-width'</span></H3>
<P>The border width properties specify the width of the <a
href="#box-border-area">border area</a>. The properties
defined in this section refer to the <span class="index-def"
title="<border-width>::definition of"><a
name="value-def-border-width"
class="value-def"><strong><border-width></strong></a></span>
value type, which may take one of the following values:</P>
<dl>
<dt><strong>thin</strong>
<dd>A thin border.
<dt><strong>medium</strong>
<dd>A medium border.
<dt><strong>thick</strong>
<dd>A thick border.
<dt><span class="value-inst-length"><strong><length></strong></span>
<dd>The border's thickness has an explicit value. Explicit
border widths cannot be negative.
</dl>
<P>The interpretation of the first three values depends on the user
agent. The following relationships must hold, however:
<P>'thin' <='medium' <= 'thick'.
<P>Furthermore, these widths must be constant throughout a document.
<!-- #include src=properties/border-top-width.srb -->
<P>These properties set the width of the top, right, bottom,
and left border of a box.
<!-- #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-left-width">'border-left-width'</span> at
the same place in the style sheet.
<P> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom borders
are set to the first value and the right and left are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<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>
<H3><A name="border-color-properties">Border color</A>:
<span class="propinst-border-top-color">'border-top-color'</span>,
<span class="propinst-border-right-color">'border-right-color'</span>,
<span class="propinst-border-bottom-color">'border-bottom-color'</span>,
<span class="propinst-border-left-color">'border-left-color'</span>, and
<span class="propinst-border-color">'border-color'</span>
</H3>
<P>The border color properties specify the color of a box's border.
<!-- #include src=properties/border-top-color.srb -->
<!-- #include src=properties/border-color.srb -->
<P>The <span class="propinst-border-color">'border-color'</span>
property sets the color of the four borders. Values have the following
meanings:</p>
<dl>
<dt><span class="index-inst" title="<color>"><span
class="value-inst-color"><strong><color></strong></span></span>
<dd>Specifies a color value.
<dt><strong>transparent</strong>
<dd>The border is transparent (though it may have width).
</dl>
<P>The <span class="propinst-border-color">'border-color'</span>
property can have from one to four component values, and the values
are set on the different sides as for <span
class="propinst-border-width">'border-width'</span>.
<P>If an element's border color is not specified
with a border property, user agents must use the value
of the element's <span
class="propinst-color">'color'</span> property as the
<a href="cascade.html#computed-value">computed value</a>
for the border color.
<div class="example">
<P>In this example, the border will be a solid black line.
<PRE>
p {
color: black;
background: white;
border: solid;
}
</PRE>
</div>
<H3><A name="border-style-properties">Border style</a>:
<span class="propinst-border-top-style">'border-top-style'</span>,
<span class="propinst-border-right-style">'border-right-style'</span>,
<span class="propinst-border-bottom-style">'border-bottom-style'</span>,
<span class="propinst-border-left-style">'border-left-style'</span>, and
<span class="propinst-border-style">'border-style'</span></H3>
<P>The border style properties specify the line style of a box's
border (solid, double, dashed, etc.). The properties defined in this
section refer to the <span class="index-def"
title="<border-style>, definition of"><a
name="value-def-border-style"><strong><border-style></strong></a></span>
value type, which may take one of the following values:</p>
<dl>
<dt><strong><span class="index-def" title="'none'::as border style"><a name="value-def-bo-none" class="value-def">none</a></span></strong>
<dd>No border; the computed border width is zero.
<dt><strong><span class="index-def" title="'hidden'"><a name="value-def-hidden" class="value-def">hidden</a></span></strong>
<dd>Same as 'none', except in terms of <a
href="tables.html#border-conflict-resolution">border conflict
resolution</a> for <a href="tables.html">table elements</a>.
<dt><strong><span class="index-def" title="'dotted'"><a name="value-def-dotted" class="value-def">dotted</a></span></strong>
<dd>The border is a series of dots.
<dt><strong><span class="index-def" title="'dashed'"><a name="value-def-dashed" class="value-def">dashed</a></span></strong>
<dd>The border is a series of short line segments.
<dt><strong><span class="index-def" title="'solid'"><a name="value-def-solid" class="value-def">solid</a></span></strong>
<dd>The border is a single line segment.
<dt><strong><span class="index-def" title="'double'"><a name="value-def-double" class="value-def">double</a></span></strong>
<dd>The border is two solid lines. The sum of
the two lines and the space between them
equals the value of <span
class="propinst-border-width">'border-width'</span>.
<dt><strong><span class="index-def" title="'groove'"><a name="value-def-groove" class="value-def">groove</a></span></strong>
<dd>The border looks as though it were carved
into the canvas.
<dt><strong><span class="index-def" title="'ridge'"><a name="value-def-ridge" class="value-def">ridge</a></span></strong>
<dd>The opposite of 'groove': the border
looks as though it were coming out of the canvas.
<dt><strong><span class="index-def" title="'inset'"><a name="value-def-inset" class="value-def">inset</a></span></strong>
<dd>The border makes the box look as though
it were embedded in the canvas.
<dt><strong><span class="index-def" title="'outset'"><a name="value-def-outset" class="value-def">outset</a></span></strong>
<dd>The opposite of 'inset': the
border makes the box look as though
it were coming out of the canvas.
</dl>
<P>All borders are drawn on top of the box's background. The color of
borders drawn for values of 'groove', 'ridge', 'inset', and 'outset'
depends on the element's <a href="#border-color-properties">border
color properties</a>, but UAs may choose their own algorithm to
calculate the actual colors used. For instance, if the 'border-color'
has the value 'silver', then a UA could use a gradient of colors from
white to dark gray to indicate a sloping border.
<!-- Remove? BB 29 Apr 2003
<P><span class="index-inst" title="conformance"><a
href="conform.html#conformance">Conforming HTML user agents</a></span> may
interpret 'dotted', 'dashed', 'double', 'groove', 'ridge',
'inset', and 'outset' to be 'solid'.
-->
<!-- #include src=properties/border-top-style.srb -->
<!-- #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 component 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.
<H3><A name="border-shorthand-properties">Border shorthand properties</a>:
<span class="propinst-border-top">'border-top'</span>,
<span class="propinst-border-right">'border-right'</span>,
<span class="propinst-border-bottom">'border-bottom'</span>,
<span class="propinst-border-left">'border-left'</span>, and
<span class="propinst-border">'border'</span></h3>
<!-- #include src=properties/border-top.srb -->
<P> This is a shorthand property for setting the width, style, and
color of the top, right, bottom, and left border of a box.
<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 are set to
their <a href="about.html#initial-value">initial values</a>. Since
the following rule does not specify a border color, the border will
have the color specified by the <span class="propinst-color">
'color'</span> property:
<PRE>
H1 { border-bottom: thick solid }
</PRE>
</div>
<!-- #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 for
all four borders of a box. 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.
<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 is
important.
<div class="example"><P>
Consider this example:
<PRE>
blockquote {
border: solid red;
border-left: double;
color: black;
}
</PRE>
<P> In the above example, the color of the left border is 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>
<h2><a name="bidi-box-model">The box model for inline elements in bidirectional context</a></h2>
<p>For each line box, UAs must take the inline boxes generated for
each element and render the margins, borders and padding in visual
order (not logical order).
<p>When the element's <span
class=propinst-direction>'direction'</span> property is 'ltr', the
left-most generated box of the first line box in which the element
appears has the left margin, left border and left padding, and the
right-most generated box of the last line box in which the element
appears has the right padding, right border and right margin.
<p>When the element's <span
class=propinst-direction>'direction'</span> property is 'rtl', the
right-most generated box of the first line box in which the element
appears has the right padding, right border and right margin, and the
left-most generated box of the last line box in which the element
appears has the left margin, left border and left padding.
</BODY>
</HTML>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.dcl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
End:
-->