Sun, 31 Jan 2016 15:42:31 -0800
change //dev.w3.org/csswg/ urls to //drafts.csswg.org/
1 <h1>CSS Overflow Module Level 3</h1>
2 <pre class="metadata">
3 Status: ED
4 Work Status: Exploring
5 ED: https://drafts.csswg.org/css-overflow/
6 Shortname: css-overflow
7 Group: csswg
8 Level: 3
9 TR: http://www.w3.org/TR/css-overflow-3/
10 Previous version: http://www.w3.org/TR/2013/WD-css-overflow-3-20130418/
11 Editor: L. David Baron, Mozilla, http://dbaron.org/
12 Editor: Florian Rivoal, Invited Expert, [email protected], http://florian.rivoal.net
13 Abstract: This module contains the features of CSS relating to scrollable overflow handling in visual media.
14 !Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css-overflow/Overview.bs">from 27 January 2015 to the present</a>
15 !Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css-overflow/Overview.src.html">from 28 March 2013 to 27 January 2015</a>
16 !Change Log: <a href="https://hg.csswg.org/drafts/log/tip/css3-overflow/Overview.src.html">from 31 July 2012 to 27 March 2013</a>
17 Ignored Vars: B, P
18 Ignored Terms: padding edge
19 </pre>
20 <!-- FIXME: Regressions from bikeshed conversion: -->
21 <!-- - Value lines in propdef tables no longer link to #values. -->
22 <!-- - no longer says "Test suite: none yet" -->
23 <!-- - Abstract has the most introductory sentence last -->
24 <!-- FIXME: other bikeshed issues -->
25 <pre class="link-defaults">
26 spec:css-transforms-1; type:property; text:transform-style
27 type: dfn; spec:css-multicol-1; text:overflow column
28 </pre>
29 <!-- FIXME: the break-* link doesn't actually work! -->
30 <pre class="anchors">
31 url: http://www.w3.org/TR/2008/CR-css3-marquee-20081205/#the-overflow-style; type: property; text: overflow-style;
32 </pre>
34 <h2 id="intro">
35 Introduction</h2>
37 In CSS Level 1 [[CSS1]], placing more content than would fit
38 inside an element with a specified size
39 was generally an authoring error.
40 Doing so caused the content to extend
41 outside the bounds of the element,
42 which would likely cause
43 that content to overlap with other elements.
45 CSS Level 2 [[CSS21]] introduced the 'overflow' property,
46 which allows authors to have overflow be handled by scrolling,
47 which means it is no longer an authoring error.
48 It also allows authors to specify
49 that overflow is handled by clipping,
50 which makes sense when the author's intent
51 is that the content not be shown.
53 This specification introduces the long-standing de-facto 'overflow-x' and 'overflow-y' properties,
54 and defines overflow handling more fully.
56 [Something something 'max-lines'.]
58 <!--
59 ââââââââ ââ ââ ââââââââ ââââââââ ââââââ
60 ââ ââ ââ ââ ââ ââ ââ ââ
61 ââ ââââ ââ ââ ââ ââ
62 ââ ââ ââââââââ ââââââ ââââââ
63 ââ ââ ââ ââ ââ
64 ââ ââ ââ ââ ââ ââ
65 ââ ââ ââ ââââââââ ââââââ
66 -->
68 <h2 id="overflow-concepts">
69 Types of overflow</h2>
71 CSS uses the term <dfn export>overflow</dfn> to describe
72 the contents of a box
73 that extend outside one of that box's edges
74 (i.e., its <i>content edge</i>, <i>padding edge</i>,
75 <i>border edge</i>, or <i>margin edge</i>).
76 The term might be interpreted as
77 elements or features that cause this overflow,
78 the non-rectangular region occupied by these features,
79 or, more commonly,
80 the minimal rectangle that bounds that region.
81 A box's overflow is computed based on the layout and styling of the box itself
82 and of all descendants whose <a>containing block chain</a>
83 includes the box.
85 In most cases, <a>overflow</a>
86 can be computed for any box
87 from the bounds and properties of that box itself,
88 plus the <a>overflow</a>
89 of each of its children.
90 However, this is not always the case; for example,
91 when ''transform-style: preserve-3d'' [[CSS3-TRANSFORMS]] is used on
92 some of the children, any of their descendants with
93 ''transform-style: preserve-3d'' must also be examined.
95 There are three different types of overflow,
96 which are used for different purposes by the UA:
98 <ul>
99 <li><a>ink overflow</a>
100 <li><a>scrollable overflow</a>
101 <li><a>border-box overflow</a>
102 </ul>
104 <h3 id="ink">Ink overflow</h3>
106 The <dfn export>ink overflow</dfn> of a box
107 is the part of that box and its contents that
108 creates a visual effect outside of
109 the box's border box.
110 Ink overflow is the overflow of painting effects defined to not affect layout
111 or otherwise extend the <a>scrollable overflow region</a>,
112 such as <a href="http://www.w3.org/TR/css-backgrounds/#box-shadow">box shadows</a>,
113 <a href="">border images</a>,
114 <a href="https://www.w3.org/TR/css-text-decor-3/">text decoration</a>,
115 overhanging glyphs (with negative side bearings,
116 or with ascenders/descenders extending outside the em box),
117 <a href="https://www.w3.org/TR/CSS2/ui.html#dynamic-outlines">outlines</a>,
118 etc.
120 Issue: What about 'hanging-punctuation'?
122 Since some effects in CSS (for example, the blurs in
123 'text-shadow' [[CSS3TEXT]] and 'box-shadow' [[CSS3BG]])
124 do not define what visual extent they cover, the extent
125 of the <a>ink overflow</a> is undefined.
127 The <dfn export>ink overflow region</dfn> is the non-rectangular area
128 occupied by the <a>ink overflow</a>, and the
129 <dfn export>ink overflow rectangle</dfn> is
130 the minimal rectangle whose axis is aligned to the box's axes
131 and contains the <a>ink overflow region</a>.
132 Note that the <a>ink overflow rectangle</a> is a rectangle
133 in the box's coordinate system, but might be non-rectangular
134 in other coordinate systems due to transforms [[CSS3-TRANSFORMS]].
137 <h3 id="scrollable">
138 Scrollable overflow</h3>
140 The <dfn export>scrollable overflow</dfn> of a box is the
141 set of things extending outside of that box's padding edge
142 for which a scrolling mechanism needs to be provided.
144 The <dfn export>scrollable overflow region</dfn> is the non-rectangular region
145 occupied by the <a>scrollable overflow</a>, and the
146 <dfn export>scrollable overflow rectangle</dfn> is
147 the minimal rectangle whose axis is aligned to the box's axes
148 and contains the <a>scrollable overflow region</a>.
150 The <a>scrollable overflow region</a> is the union of:
151 <ul>
152 <li>the boxâs own content and padding areas
153 <li>all line boxes directly contained by the box
154 <li>the margin boxes <em>unioned with</em> the border boxes
155 of all boxes for which it is the containing block
156 (accounting for transforms as described below).
157 Issue: Only Blink (and presumably WebKit) use the margin box for abspos; other browsers use the border box.
158 Can we convince everyone else to change? Because using the border box is kindof hostile.
159 <!-- testcase: http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cstyle%3E%0A%20%20div%20%7B%20height%3A%2050px%3B%20overflow%3A%20scroll%3B%20border%3A%20solid%3B%20position%3A%20relative%3B%7D%0A%20%20p%20%7B%20margin%3A%2025px%3B%20background%3A%20red%3B%20%7D%0A%20%20q%20%7B%20position%3A%20absolute%3B%20background%3A%20blue%3B%20top%3A%2025px%3B%20margin%3A%2025px%3B%20%7D%0A%3C%2Fstyle%3E%0A%3Cdiv%3E%0A%20%20%3Cp%3ETest%20%3Cq%3ETest2%0A%3C%2Fdiv%3E -->
161 <li>the <a>scrollable overflow regions</a> of all of the above boxes
162 (accounting for transforms as described below),
163 provided they themselves have ''overflow: visible''
164 (i.e. do not themselves trap the overflow)
165 and that overflow is not already clipped
166 by the 'clip' or 'clip-path' properties.
168 Issue: What about masking?
169 </ul>
171 <p class="issue">
172 The following definition should be rewritten to use
173 the concept of <a href="https://drafts.csswg.org/css-transforms/#3d-rendering-context">3D rendering context</a> [[!CSS3-TRANSFORMS]]
174 and related terms,
175 particularly once those concepts stabilize following changes
176 proposed in the CSS WG meeting on the morning of 2014-01-28.
178 Given the following definitions
179 <span class="issue">which belong in [[CSS3-TRANSFORMS]]</span>:
181 <dl>
182 <dt><dfn>3d-preserving child</dfn>
183 <dd>
184 A child box <var>B</var> of a containing block <var>C</var>
185 is a 3d-preserving child
186 if it has ''transform-style: preserve-3d''
187 and the user-agent is not required to flatten it
188 based on the <a href="http://www.w3.org/TR/css3-transforms/#transform-style-property">requirements</a> in [[!CSS3-TRANSFORMS]].
190 <dt><dfn>non-3d-preserving child</dfn>
191 <dd>
192 A child <var>C</var> of a box <var>P</var> is a non-3d-preserving-child
193 if it is not a <a>3d-preserving child</a>.
195 <dt><dfn>3d-preserving descendant</dfn>
196 <dd>
197 Box <var>D</var> is a 3d-preserving descendant of box <var>A</var>
198 if <var>A</var> is an ancestor of D,
199 and <var>D</var> and all of the boxes (if any)
200 in the <a>containing block chain</a> from <var>D</var> to <var>A</var>
201 are <a>3d-preserving child</a> boxes.
202 </dl>
204 The <a>scrollable overflow</a> of a box is the union of the following things,
205 all adjusted for transforms <span class="issue">undefined concept!</span> into the box's coordinate space:
207 <ul>
208 <li>
209 for the box and all of its <a>3d-preserving descendant</a> boxes:
210 <ul>
211 <li>the box's own padding edge (for the box itself) or border edge (for <a>3d-preserving descendant</a> boxes)</li>
212 <li>the bounds <span class="issue">undefined term!</span> of any text directly in the box</li>
213 <li><span class="issue">MORE HERE!</span>
214 </ul>
215 <li>
216 for all the <a>non-3d-preserving child</a> boxes of the
217 box and its <a>3d-preserving descendant</a> boxes,
218 the scrollable overflow of the box
219 </li>
220 </ul>
222 <p class="issue">
223 I wrote this definition off the top of my head,
224 so it can't possibly be right.
225 It's missing tons of pieces!
227 <p class="issue">
228 The handling of preserve-3d subtrees here is probably wrong;
229 the elements should probably count
230 only towards the overflow of the element that flattens them.
232 Note that the <a>scrollable overflow rectangle</a> is a always rectangle
233 in the box's own coordinate system, but might be non-rectangular
234 in other coordinate systems due to transforms [[CSS3-TRANSFORMS]].
236 Issue: Browsers seem to agree on using axis-aligned rectangles (in the element's own coord space)
237 to determine overflow.
238 This means scrollbars can appear when not actually necessary.
239 See <a href="http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Cdiv%20class%3Dparent%3E%3Cdiv%20class%3Dchild%3E%3Cdiv%20class%3D%27grandchild%27%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%3C%2Fdiv%3E%0A%3Cstyle%3E%0Adiv%20{%20padding%3A%2030px%3B%20min-width%3A%2030px%3B%20float%3A%20left%3B%20border%3A%20thin%20dotted%3B%20background%3A%20rgba%280%2C0%2C0%2C.2%29%3B}%0A.parent%20{%20overflow%3A%20auto%3B%20background%3A%20rgba%28255%2C0%2C0%2C.2%29%3B%20}%0A.child%20{%20transform%3A%20rotate%28-45deg%29%3B%20padding%3A%203px%3B%20background%3A%20rgba%280%2C255%2C0%2C.2%29%3B%20}%0A.grandchild%20{%20transform%3A%20rotate%2845deg%29%20scale%28.9%29%3B%20background%3A%20rgba%280%2C0%2C255%2C.2%29%3B%20}">testcase</a>
240 (adjust the ''scale(.9)'' to ''scale(.7)'' to see the scrollbars disappear,
241 as the blue grandchild is no longer growing the bounds of the green child).
242 Is this behavior we want to spec,
243 or is it something browsers would like to fix someday?
246 <h3 id="border-box">
247 Border box overflow</h3>
249 <p class="issue">
250 This concept has been proposed for some uses, such as for
251 determining what the 'outline' property goes around, and
252 as the basis of a coordinate system for specifying clips and masks,
253 but it's not clear if it's needed.
255 The <dfn>border-box overflow</dfn> of a box is the
256 union of the box's border edge and the border edges of
257 the box's descendants.
259 <p class="issue">
260 If needed, define more formally, as for scrollable overflow above.
261 (Maybe even share the definitions in an appropriate way!)
263 The <dfn>border-box overflow region</dfn> is the non-rectangular region
264 occupied by the <a>border-box overflow</a>, and the
265 <dfn>border-box overflow rectangle</dfn> is
266 the minimal rectangle whose axis is aligned to the box's axes
267 and contains the <a>border-box overflow region</a>.
268 Note that the <a>border-box overflow rectangle</a> is a rectangle
269 in the box's coordinate system, but might be non-rectangular
270 in other coordinate systems due to transforms [[CSS3-TRANSFORMS]].
273 <!--
274 âââââââ ââ ââ ââââââââ ââââââââ ââââââââ ââ âââââââ ââ ââ
275 ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ
276 ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ
277 ââ ââ ââ ââ ââââââ ââââââââ ââââââ ââ ââ ââ ââ ââ ââ âââââââ âââââââââ
278 ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ
279 ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ ââ
280 âââââââ âââ ââââââââ ââ ââ ââ ââââââââ âââââââ âââ âââ
281 -->
283 <h2 id="overflow-properties">
284 Scrollable Overflow: the 'overflow-x', 'overflow-y', and 'overflow' properties</h2>
286 These properties specify whether a boxâs content
287 (including any <a>ink overflow</a>)
288 is clipped to its padding edge,
289 and if so,
290 whether it is a <dfn export>scrollable box</dfn>
291 that allows the user to scroll clipped parts of its <a>scrollable overflow region</a>
292 into view.
294 <pre class=propdef>
295 Name: overflow-x, overflow-y
296 Value: ''visible'' | ''hidden'' | ''clip'' | ''scroll'' | ''auto''
297 Initial: ''visible''
298 Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
299 Inherited: no
300 Percentages: N/A
301 Media: visual
302 Computed value: see below
303 Animatable: no
304 </pre>
306 The 'overflow-x' property specifies
307 the handling of <a>overflow</a> in the horizontal direction
308 (i.e., overflow from the left and right sides of the box),
309 and the 'overflow-y' property specifies the handling
310 of <a>overflow</a> in the vertical direction
311 (i.e., overflow from the top and bottom sides of the box).
313 <pre class=propdef>
314 Name: overflow
315 Value: ''visible'' | ''hidden'' | ''clip'' | ''scroll'' | ''auto''
316 Initial: see individual properties
317 Applies to: block containers [[!CSS21]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]]
318 Inherited: no
319 Percentages: N/A
320 Media: visual
321 Computed value: see individual properties
322 Animatable: no
323 Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
324 </pre>
326 The 'overflow' property is a shorthand property
327 that sets the specified values of both 'overflow-x' and 'overflow-y'
328 to the value specified for 'overflow'.
330 Values have the following meanings:
332 <dl dfn-for="overflow, overflow-x, overflow-y" dfn-type="value">
333 <dt><dfn>visible</dfn>
334 <dd>
335 There is no special handling of overflow, that is, it
336 may be rendered outside the box.
337 The box is not a <a>scrollable box</a>.
339 <dt><dfn>hidden</dfn>
340 <dd>
341 This value indicates that
342 the boxâs content is clipped to its padding box
343 and that no scrolling user interface should be provided by the UA
344 to view the content outside the clipping region.
345 However, the content may still be scrolled programatically,
346 for example using the mechanisms defined in [[CSSOM-VIEW]],
347 and the box is therefore still a <a>scrollable box</a>.
349 <dt><dfn>clip</dfn>
350 <dd>
351 Like ''hidden'',
352 this value indicates that
353 the boxâs content is clipped to its padding box
354 and that no scrolling user interface should be provided by the UA
355 to view the content outside the clipping region.
356 In addition, unlike ''overflow: hidden''
357 which still allows programmatic scrolling,
358 ''overflow: clip'' forbids scrolling entirely,
359 through any mechanism,
360 and therefore the box is not a <a>scrollable box</a>.
362 Issue: Mozilla implements -moz-hidden-unscrollable,
363 which is similar to ''clip'',
364 except that it does not cause the element to establish a BFC.
365 Should we match that?
367 <dt><dfn>scroll</dfn>
368 <dd>
369 This value indicates that
370 the content is clipped to the padding box,
371 but can be scrolled into view
372 (and therefore the box is a <a>scrollable box</a>).
373 Furthermore, if the user agent uses a scrolling mechanism
374 that is visible on the screen (such as a scroll bar or a panner),
375 that mechanism should be displayed
376 whether or not any of its content is clipped.
377 This avoids any problem with scrollbars appearing
378 and disappearing in a dynamic environment.
379 When this value is specified and the target medium is ''print'',
380 overflowing content may be printed.
382 <dt><dfn>auto</dfn>
383 <dd>
384 This value indicates that
385 the boxâs content is clipped to the padding box,
386 but can be scrolled into view
387 (and therefore the box is a <a>scrollable box</a>).
388 However, if the user agent uses a scrolling mechanism
389 that is visible on the screen (such as a scroll bar or a panner),
390 that mechanism should only be displayed
391 if there is overflow.
392 </dl>
394 If the computed value of 'overflow' on a <a>block box</a> is not ''overflow/visible'',
395 it creates a new <a>block formatting context</a> for its content.
397 <h3 id="overflow-computed-values">
398 Overflow Value Computation and Propagation</h3>
400 <p>The computed values of 'overflow-x' and 'overflow-y'
401 are determined from the <a>specified values</a> [[!CSS3CASCADE]]
402 based on the following rules:
404 <ol>
405 <li>
406 If one <a>specified value</a> is ''overflow/visible''
407 and the other is not,
408 then computed values are the <a>specified values</a>
409 with ''overflow/visible'' changed to ''overflow/auto''.
410 </li>
411 <li>
412 Otherwise, if both <a>specified values</a> are ''overflow/visible''
413 and the computed value of 'contain' is
414 one that activates <a>paint containment</a>
415 (e.g. ''contain:strict''
416 or ''contain: paint''
417 or ''contain: layout paint''â¦),
418 then the computed values of both 'overflow-x' and 'overflow-y'
419 are changed to ''overflow/clip''.</li>
420 <li>
421 Otherwise, the computed values are as specified.
422 </li>
423 </ol>
424 </div>
426 UAs must apply the 'overflow' property
427 set on the root element to the viewport.
428 For HTML UAs,
429 if this would result in the viewport having ''visible'' overflow,
430 the UA must instead apply the 'overflow' property
431 set on the <{body}> element to the viewport.
432 In either case,
433 the used value of 'overflow' for the element from which the value is propagated
434 must evaluate to ''visible''.
436 If this application would result in the viewport having ''visible'' overflow,
437 the UA must instead treat the viewport as having ''overflow/auto'' overflow.
439 <h3 id="scrollbar-layout">
440 Scrollbars and Layout</h3>
442 In the case of a scrollbar being placed on an edge of the element's box,
443 it should be inserted between the inner border edge
444 and the outer padding edge.
445 Any space taken up by the scrollbars should be
446 taken out of (subtracted from the dimensions of)
447 the containing block formed by the element with the scrollbars.
449 Issue: import examples from [[CSS3-BOX]].
451 <h3 id="scrolling-direction">
452 Scrolling Origin, Direction, and Restriction</h3>
454 The <dfn export>initial scroll position</dfn>,
455 that is, the initial position of
456 the boxâs <a>scrollable overflow region</a>
457 with respect to its border box,
458 prior to any user or programmatic scrolling that changes it,
459 is dependent on the boxâs <a>writing mode</a>,
460 and is by default the <a>block-start</a>/</a>inline-start</a> edge
461 of the boxâs <a>padding edge</a>.
462 However, the 'align-content' and 'justify-content' properties [[!CSS-ALIGN-3]]
463 can be used to change this.
465 Due to Web-compatibility constraints
466 (caused by authors exploiting legacy bugs to surreptitiously hide content from visual readers but not search engines and/or speech output),
467 UAs must clip the <a>scrollable overflow region</a>
468 of <a>scrollable boxes</a>
469 on the <a>block-start</a> and </a>inline-start</a> sides of the box
470 (thereby behaving as if they had no <a>scrollable overflow</a> on that side).
472 The viewport uses the <a>principal writing mode</a> for these calculations.
474 <p class="issue">
475 [[CSS3-MARQUEE]] describes an 'overflow-style' property,
476 but it has not picked up implementation experience
477 that the working group is aware of.
478 Should this document treat 'overflow-style' as a defunct proposal,
479 or should this document describe the 'overflow-style' property
480 and attempt to revive it,
481 despite that implementations have implemented
482 'overflow-x' and 'overflow-y' instead?
485 <h2 id="max-lines">
486 Limiting Number of Visible Text Lines: the 'max-lines' property</h2>
489 <pre class=propdef>
490 Name: max-lines
491 Value: none | <<integer>>
492 Initial: none
493 Applies to: all non-inline elements
494 Inherited: no
495 Animatable: as integer
496 Percentages: N/A
497 Media: visual
498 Computed value: specified value
499 </pre>
501 Issue: Add back 'max-lines', so we can kill the unspecified WebKit feature that does this poorly.
504 <h2 id="static-media">
505 Overflow in static media</h2>
507 <p class="issue">
508 This specification should define useful behavior
509 for all values of 'overflow'
510 in static media (such as print).
511 Current implementation behavior is quite poor and
512 produces unexpected results when authors have not considered
513 what will happen when
514 the content they produce for interactive media
515 is printed.
518 Privacy and Security Considerations {#priv-sec}
519 ===============================================
521 This specification introduces no new privacy or security concerns.
523 <h2 class=no-num id="acknowledgments">
524 Acknowledgments</h2>
526 <p>
527 Thanks especially to the feedback from
528 Rossen Atanassov,
529 Bert Bos,
530 Tantek Ãelik,
531 John Daggett,
532 fantasai,
533 Daniel Glazman,
534 Vincent Hardy,
535 Håkon Wium Lie,
536 Peter Linss,
537 Robert O'Callahan,
538 Florian Rivoal,
539 Alan Stearns,
540 Steve Zilles,
541 and all the rest of the
542 <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.