-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
607 lines (498 loc) · 21.6 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<h1>CSS Display Module Level 3</h1>
<pre class='metadata'>
Status: WD
Date: 2014-09-11
ED: http://dev.w3.org/csswg/css-display/
Shortname: css-display
Group: csswg
Level: 3
TR: http://www.w3.org/TR/css-display-3/
Previous Version: http://www.w3.org/TR/2014/WD-css-display-3-20140220/
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
Editor: fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Abstract: This module describes how the CSS formatting box tree is generated from the document element tree and defines the 'display' and 'box-suppress' properties that control it.
Ignored Terms: display-model, display-role, table row group box, ruby container
Link Defaults: css-lists-3 (property) counter-increment
</pre>
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
The 'display' property, introduced in CSS 2.1,
defines what kind of boxes an element generates
(and whether it generates boxes at all),
and how it lays out its contents.
These concepts are actually rather independent,
though they're conflated by the 'display' property.
This causes some pain when a property value intended to affect one aspect
(such as setting an element to ''display:none'' to suppress box generation)
affects another aspect
(such as losing the memory of what it was <em>before</em> ''display:none'',
so that it can be set back to that value later).
This specification subsumes the CSS 2.1 definition of the 'display' property,
and redefines it to be a shorthand property for a small family of longhands,
each controlling an independent aspect of an element's "display".
<h3 id="placement">
Module interactions</h3>
This specification transforms the 'display' property into a shorthand property,
and defines several longhand properties that it expands into or effects.
This module replaces and extends the definition of the 'display' property defined in [[!CSS21]] section 9.2.4.
None of the properties in this module apply to the <code>::first-line</code> or <code>::first-letter</code> pseudo-elements.
<h3 id="values">
Values</h3>
This specification follows the
<a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from [[!CSS21]]. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].
Other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the
<a href="http://www.w3.org/TR/css3-values/#common-keywords">CSS-wide keywords</a>
as their property value. For readability it has not been repeated explicitly.
<h2 id='the-display-properties'>
Controlling Layout Modes</h2>
The 'display' shorthand and its associated family of properties control the layout mode of elements
(how the element determines the sizes and positions of itself and its descendants),
and what boxes they and their descendants generate.
<h3 id='the-display-inside'>
Telling Contents How to Lay Out: the 'display-inside' property</h3>
<pre class="propdef">
Name: display-inside
Value: auto | block | table | flex | grid | ruby
Initial: auto
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: a keyword
Media: all
</pre>
The 'display-inside' property specifies the <dfn export>inner display type</dfn>
of the box generated by the element,
dictating how its contents lay out
inside the box.
<dl dfn-type="value" dfn-for="display-inside">
<dt><dfn>auto</dfn>
<dd>
If the element's computed 'display-outside' value is ''inline-level'',
the element is an inline element,
and lays out its contents using inline layout. [[!CSS21]]
If the element's computed 'display-outside' value is an <a>layout-specific internal type</a>,
this elements acts as normal for its given 'display-outside' value.
Otherwise, this value computes to ''display-inside/block''.
<dt><dfn>block</dfn>
<dd>
The element lays out its contents using block layout. [[!CSS21]]
<dt><dfn>table</dfn>
<dd>
The element lays out its contents using table layout. [[!CSS21]]
<dt><dfn>flex</dfn>
<dd>
The element lays out its contents using flex layout. [[!CSS3-FLEXBOX]]
<dt><dfn>grid</dfn>
<dd>
The element lays out its contents using grid layout. [[!CSS3-GRID-LAYOUT]]
<dt><dfn>ruby</dfn>
<dd>
The element lays out its contents using ruby layout. [[!CSS3RUBY]]
</dl>
<h3 id='the-display-outside'>
Interacting with Ancestors and Siblings: the 'display-outside' property</h3>
<pre class="propdef">
Name: display-outside
Value: block-level | inline-level | run-in | contents | none | table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-container
Initial: inline-level
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: as specified
Media: all
</pre>
The 'display-outside' property specifies the <dfn export>outer display type</dfn>
of the box generated by the element,
dictating how the element participates in its parent formatting context.
<dl dfn-type="value" dfn-for="display-outside">
<dt><dfn>block-level</dfn>
<dd>
The element generates a <dfn dfn>block-level box</dfn>,
and participates in a block formatting context.
Other formatting contexts,
such as flex formatting contexts,
may also work with block-level elements. [[!CSS21]]
<dt><dfn>inline-level</dfn>
<dd>
The element generates an <dfn dfn>inline-level box</dfn>,
and participates in an inline formatting context. [[!CSS21]]
<dt><dfn>run-in</dfn>
<dd>
The element generates a <a>run-in box</a>.
Run-in elements act like inlines or blocks,
depending on the surrounding elements.
See [[#run-in]] for details.
<dt><dfn>contents</dfn>
<dd>
The element itself does not generate any boxes,
but its children and pseudo-elements still generate boxes as normal.
For the purposes of box generation and layout,
the element must be treated as if it had been replaced with its children and pseudo-elements in the document tree.
Issue: ''display-outside/contents'' currently only has an effect on box generation and layout.
Other things that care about the document tree are unaffected, like counter scopes.
Is this what we want?
<dt><dfn>none</dfn>
<dd>
The element generates no boxes,
and does not participate in any formatting context.
Note: This value exists for legacy reasons,
and interacts with the separate 'box-suppress' property.
Advisement: It is recommended that 'box-suppress' be used instead of ''display: none'',
so that the element's display type is automatically preserved
for when it's no longer suppressed.
<dt><dfn>table-row-group</dfn>, <dfn>table-header-group</dfn>, <dfn>table-footer-group</dfn>, <dfn>table-row</dfn>, <dfn>table-cell</dfn>, <dfn>table-column-group</dfn>, <dfn>table-column</dfn>, <dfn>table-caption</dfn>
<dd>
The element is an <dfn dfn>internal table element</dfn>,
and participates in a table layout context. [[!CSS21]]
''display-outside/table-cell'' and ''display-outside/table-caption'' are <a>layout-specific leaf types</a>;
the rest are <a>layout-specific internal types</a>.
<dt><dfn>ruby-base</dfn>, <dfn>ruby-text</dfn>, <dfn>ruby-base-container</dfn>, <dfn>ruby-text-container</dfn>
<dd>
The element is an <dfn dfn>internal ruby element</dfn>,
and participates in a ruby layout context. [[!CSS3RUBY]]
''ruby-base'' and ''ruby-text'' are <a>layout-specific leaf types</a>;
''ruby-base-container'' and ''ruby-text-container'' are <a>layout-specific internal types</a>.
</dl>
Some values of 'display-outside' are specialized for particular formatting contexts,
and don't have meaning outside of those specific contexts:
<dl>
<dt><dfn>layout-specific internal types</dfn>
<dd>
These display types require their parent and children to be of particular display types.
For example, a ''table-row'' box requires its parent to be a <a>table row group box</a>
and its children to be ''display-outside/table-cell'' boxes.
<dt><dfn>layout-specific leaf types</dfn>
<dd>
These display types require their parent to be of a particular display type,
but can accept any 'display-inside' value.
For example, a ''display-outside/table-caption'' box must have a ''display-inside/table'' parent,
but can establish any kind of formatting context for its children.
</dl>
Boxes with layout-specific types generate wrapper boxes around themselves
when placed in an incompatible parent,
as defined by their respective specifications.
<h3 id='display-list'>
Creating List Markers: the 'display-list' property</h3>
<pre class="propdef">
Name: display-list
Value: none | list-item
Initial: none
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: as specified
Media: all
</pre>
<dl dfn-type="value" dfn-for="display-list">
<dt><dfn>list-item</dfn>
<dd>
The element generates a <code>::marker</code> pseudo-element
and is considered a <a>list item</a>.
</dl>
<h3 id='the-display'>
The 'display' shorthand property</h3>
<pre class="propdef">
Name: display
Value: [ <<'display-inside'>> || <<'display-outside'>> || <<'display-list'>> ] | inline | inline-list-item | inline-table | inline-flex | inline-grid
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Computed value: see individual properties
Animatable: see individual properties
Media: see individual properties
</pre>
The 'display' <a>shorthand property</a> sets all the display type properties in one declaration:
'display-outside', 'display-inside', and 'display-list'.
If only one keyword is specified
or only one keyword is specified together with ''display-list/list-item'',
the shorthand expands as specified below:
<table dfn-type="value" dfn-for="display" class='data'>
<thead>
<tr>
<th>'display'
<th>'display-outside'
<th>'display-inside'
<tbody>
<tr>
<th><dfn export>inline</dfn>
<td>''inline-level''
<td>''auto''
<tr>
<th><dfn export>block</dfn>
<td>''block-level''
<td>''display-inside/block''
<tr>
<th><dfn export>inline-block</dfn>
<td>''inline-level''
<td>''display-inside/block''
<tr>
<th><dfn>list-item</dfn> <a href="#list-item-note">*</a>
<td>''block-level''
<td>''display-inside/block''
<tr>
<th><dfn>inline-list-item</dfn> <a href="#list-item-note">*</a>
<td>''inline-level''
<td>''auto''
<tbody>
<tr>
<th><dfn>table</dfn>
<td>''block-level''
<td>''display-inside/table''
<tr>
<th><dfn>inline-table</dfn>
<td>''inline-level''
<td>''display-inside/table''
<tr>
<th><dfn>table-caption</dfn>
<td>''display-outside/table-caption''
<td>''display-inside/block''
<tr>
<th><dfn>table-cell</dfn>
<td>''display-outside/table-cell''
<td>''display-inside/block''
<tbody>
<tr>
<th><dfn>flex</dfn>
<td>''block-level''
<td>''display-inside/flex''
<tr>
<th><dfn>inline-flex</dfn>
<td>''inline-level''
<td>''display-inside/flex''
<tbody>
<tr>
<th><dfn>grid</dfn>
<td>''block-level''
<td>''display-inside/grid''
<tr>
<th><dfn>inline-grid</dfn>
<td>''inline-level''
<td>''display-inside/grid''
<tbody>
<tr>
<th><dfn>ruby</dfn>
<td>''inline-level''
<td>''display-inside/ruby''
<tbody>
<tr>
<th><dfn>none</dfn>
<td>''display-outside/none''
<td>''display-inside/block''
<tr>
<th><dfn>contents</dfn>
<td>''display-outside/contents''
<td>''display-inside/block''
<tbody>
<tr>
<th><var>all other <<'display-outside'>></var>
<td><<'display-outside'>>
<td>''auto''
</table>
<span id="list-item-note">* For ''display/list-item'' and ''display/inline-list-item'', additionally set 'display-list' to ''display-list/list-item''.
<h3 id='transformations'>
Automatic Box Type Transformations</h3>
Some layout effects require <dfn export title="blockify|blockification">blockification</dfn>
or <dfn export title="inlinify|inlinification">inlinification</dfn> of the box type,
causing the box’s 'display-outside' property, if it is not ''display-outside/none'' or ''display-outside/contents'',
to compute to ''block-level'' or ''inline-level'' (respectively).
<div class='example'>
Some examples of this include:
<ul>
<li>Absolute positioning or floating an element <a>blockifies</a> the box’s display type. [[CSS21]]
<li>Containment in a <a spec=css-ruby>ruby container</a> <a>inlinifies</a> the box’s display type, as described in [[CSS3RUBY]].
<li>A parent with a ''display-inside/grid'' or ''display-inside/flex'' 'display-inside' value <a>blockifies</a> the box’s display type. [[CSS3-GRID-LAYOUT]] [[CSS3-FLEXBOX]]
</ul>
</div>
When a box is <a>inlinified</a>,
it recursively <a>inlinifies</a> all of its in-flow children
unless it itself establishes a new formatting context,
so that no block-level descendants
break up the inline formatting context in which it participates.
The root element’s display type is always <a>blockified</a>.
Additionally, a 'display-outside' of ''display-outside/contents'' computes to ''block-level'' on the root element.
<h2 id='box-suppress'>
Controlling box generation: the 'box-suppress' property</h2>
<pre class="propdef">
Name: box-suppress
Value: show | discard | hide
Initial: show
Applies to: all elements
Inherited: no
Percentages: n/a
Computed value: see prose
Media: all
</pre>
If the computed value of 'display-outside' is ''display-outside/none'',
the computed value of 'box-suppress' is ''discard''.
Otherwise, the computed value is the specified value.
<dl dfn-type="value" dfn-for="box-suppress">
<dt><dfn>show</dfn>
<dd>
The element generates boxes as normal,
per its 'display-*' properties.
<dt><dfn>discard</dfn>
<dd>
The element generates no boxes at all.
<dt><dfn>hide</dfn>
<dd>
The element generates boxes as normal,
but those boxes do not participate in layout in any way,
and must not be displayed.
For the purpose of any layout-related information,
such as querying for the computed value of the element's 'width' property,
it must be treated as if it did not generate any boxes.
Properties that rely on boxes but do not rely on layout,
such as animations, 'counter-increment', etc.,
must work as normal on this element and its descendants.
Issue: This needs more clarity about what "layout-related" and "participates in layout" means.
Does the box still generate anonymous boxes, etc.?
Issue: How does this affect speech? Is that "layout"?
</dl>
Issue: We welcome better naming suggestions on this property.
<h2 id='run-in'>
Run-In Layout</h2>
A <dfn>run-in box</dfn> is a box that <em>merges into</em> a block that comes after it,
inserting itself at the beginning of that block’s inline-level content.
This is useful for formatting compact headlines, definitions, and other similar things,
where the appropriate DOM structure is to have a headline preceding the following prose,
but the desired display is an inline headline laying out with the text.
<div class="example">
For example, dictionary definitions are often formatted so that the word is inline with the definition:
<pre>
<dl class='dict'>
<dt>dictionary
<dd>a book that lists the words of a language in alphabetical
order and gives their meaning, or that gives the equivalent
words in a different language.
<dt>glossary
<dd>an alphabetical list of terms or words found in or relating
to a specific subject, text, or dialect, with explanations; a
brief dictionary.
</dl>
<style>
.dict > dt {
display: run-in;
}
.dict > dt::after {
content: ": "
}
</style>
</pre>
Which is formatted as:
<pre>
<b>dictionary:</b> a book that lists the words of a language
in alphabetical order and explains their meaning.
<b>glossary:</b> an alphabetical list of terms or words found
in or relating to a specific subject, text, or dialect,
with explanations; a brief dictionary.
</pre>
</div>
A <a>run-in box</a> behaves exactly as an <a>inline-level box</a>, except:
<ul>
<li>
If a <a>run-in sequence</a> is immediately followed by a block box
that does not establish a new <a>formatting context</a>,
it is inserted as direct children of the block box
after its ''::marker'' pseudo-element's boxes (if any),
but preceding any other boxes generates by the contents of the block
(including the box generated by the ''::before'' pseudo-element, if any).
The reparented content is then formatted as if originally parented there.
<span class='note'>Note that only layout is affected, not inheritance,
because property inheritance for non-anonymous boxes is based only on the element tree.</span>
<li>
Otherwise,
an anonymous block box is generated around the <a>run-in sequence</a>
and all immediately following inline-level content
(up to, but not including, the next <a>run-in sequence</a>, if any).
<li>
A <a>run-in box</a> with ''display-inside: auto'' <a>inlinifies</a> its contents.
</ul>
A <dfn>run-in sequence</dfn> is a maximal sequence of consecutive sibling <a>run-in boxes</a>
and intervening white space and/or out-of-flow boxes.
Issue: Should out-of-flow elements get reparented, left behind, or break apart the sequence?
<a href="http://lists.w3.org/Archives/Public/www-style/2012Aug/0257.html">See thread.</a>
Note: This run-in model is slightly different from the one proposed in earlier revisions of [[!CSS21]].
<h2 id='glossary'>
Glossary</h2>
The following terms are defined here for convenience:
<dl export>
<dt><dfn title="inline-level|inline-level content">inline-level</dfn>
<dd>
Content that participates in inline layout.
Specifically, inline-level boxes and text.
<dt><dfn title="block-level|block-level content">block-level</dfn>
<dd>
Content that participates in block layout.
Specifically, block-level boxes.
<dt><dfn title="inline|inline box">inline</dfn>
<dd>
A non-replaced <a>inline-level</a> box whose 'display-inside' is ''auto''.
The contents of an inline box participate in the same inline formatting context as the inline box itself.
<dt><dfn title="atomic inline|atomic inline box">atomic inline</dfn>
<dd>
An inline-level box that is replaced or that establishes a new formatting context.
(An inline-level box whose 'display-inside' is not ''auto'' establishes a new formatting context of the specified type.)
<dt><dfn title="block container|block container box">block container</dfn>
<dd>
A box whose contents participate in a block formatting context,
i.e. one whose computed 'display-inside' value is ''display-inside/block''.
<dt><dfn>block box</dfn>
<dd>
A <a>block-level box</a> that is a <a>block container</a>.
<dt><dfn>block</dfn>
<dd>
Used as a shorthand for <a>block box</a>, <a>block-level box</a>, or <a>block container box</a>,
where unambiguous.
<dt><dfn>containing block</dfn>
<dd>
A rectangle that forms the basis of sizing and positioning
for the boxes associated with it
(usually the children of the box that generated it).
Notably, a containing block is <em>not a box</em>
(it is a rectangle),
however it is often derived from the dimensions of a box.
If properties of a containing block are referenced,
they reference the values on the box that generated the containing block.
(For the <a>initial containing block</a>, the values are taken from the root element.)
See [[CSS21]] <a href="http://www.w3.org/TR/CSS21/visuren.html#containing-block">Section 9.1.2</a>
and <a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">Section 10.1</a> for details.
<dt><dfn>initial containing block</dfn>
<dd>
The <a>containing block</a> of the root element.
See <a href="http://www.w3.org/TR/CSS21/visudet.html#containing-block-details">CSS2.1§10.1</a> for continuous media;
and [[!CSS3PAGE]] for paged media.
<dt><dfn>formatting context</dfn>
<dd>
The thing that makes CSS do the layouts.
Issue: wordsmith this.
Block and inline formatting contexts are defined in CSS 2.1 Section 9.4.
</dl>
See [[!CSS21]] <a href="http://www.w3.org/TR/CSS21/visuren.html">Chapter 9</a> for a fuller definition of these terms.
<h2 class=no-num id="acknowledgments">
Acknowledgments</h2>
We would like to thank the many people who have attempted to separate out the disparate details of box generation over the years,
most particularly Bert Bos,
whose last attempt with 'display-model' and 'display-role' didn't get anywhere,
but primed us for the current spec,
and Anton Prowse,
whose relentless assault on CSS2.1 Chapter 9 forced some order out of the chaos.
We would also like to thank the many JavaScript libraries such as jQuery
which have hacked around the "what 'display' should I give it when you call .show()?" problem,
making it extremely clear that something needed to be done on our part.
<h2 class=no-num id="changes">
Changes</h2>
Changes since the <a href="http://www.w3.org/TR/2014/WD-css-display-3-20140220/">20 Feburary 2014 Working Draft</a> include:
<ul>
<li>Renamed <css>display-box</css> to 'box-suppress' and <css>display-extras</css> to 'display-list'.
<li>Moved the ''display-outside/contents'' value from 'box-suppress' to 'display-outside'.
<li>Added ''hide'' value to 'box-suppress'.
<li>Added <a>blockification</a> and <a>inlinification</a> rules.
<li>Added ''display: run-in'' and defined its layout in [[#run-in]].
<li>Various editorial improvements.
<li>Added [[#glossary]], incorporating key CSS2.1 terms.
</ul>