Title: CSS Overflow Module Level 4 Status: ED Work Status: Revising ED: https://drafts.csswg.org/css-overflow-4/ Shortname: css-overflow Group: csswg Level: 4 TR: https://www.w3.org/TR/css-overflow-4/ Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393 Editor: Florian Rivoal, On behalf of Bloomberg, http://florian.rivoal.net/, w3cid 43241 Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400 Abstract: This module contains the features of CSS relating to scrollable overflow handling in visual media. It builds on the CSS Overflow Module Level 3, defining 'line-clamp', its longhands, and its legacy pre-standard syntax; adding a 'block-ellipsis' property; and expanding 'overflow-clip-margin' with longhands. An appendix also contains a more experimental exploration of redirecting overflow by fragmentation.
type: dfn; spec:css-multicol-1; text:overflow column spec:css-pseudo-4; type:selector; text:::first-letter spec:css-pseudo-4; type:selector; text:::first-line spec:css-writing-modes-4; type:dfn; text:start spec:css-writing-modes-4; type:dfn; text:end
url: https://drafts.csswg.org/selectors-3/#subject; type: dfn; text: subject; url: https://www.w3.org/TR/CSS21/visudet.html#strut; type: dfn; text: strut;
Name: overflow-clip-margin-top, overflow-clip-margin-right, overflow-clip-margin-bottom, overflow-clip-margin-left, overflow-clip-margin-block-start, overflow-clip-margin-inline-start, overflow-clip-margin-block-end, overflow-clip-margin-inline-end Value: <> || < > Initial: ''0px'' Inherited: no Logical property group: overflow-clip-margin Applies to: boxes to which 'overflow' applies Computed value: the computed < > and a < > keyword Animation type: per computed value if the < > values match; otherwise discrete
Name: overflow-clip-margin, overflow-clip-margin-inline, overflow-clip-margin-block Value: <These properties and their shorthands define the overflow clip edge of the box, i.e. precisely how far outside its bounds the box’s content is allowed to paint before being clipped by effects (such as ''overflow: clip'', above) that are defined to clip to the box’s [=overflow clip edge=]. The [=shorthand=]/[=longhand=] relationships are as for 'margin', but note that the [=shorthands=] have a restricted syntax. Values are defined as follows:> || < > Initial: ''0px'' Inherited: no Applies to: boxes to which 'overflow' applies
Name: text-overflow Value: [ clip | ellipsis | <ISSUE: This section might need to be re-synced against [[CSS-OVERFLOW-3]]. This property specifies rendering when inline content overflows its line box edge in the inline progression direction of its block container element ("the block") that has 'overflow' other than ''overflow/visible''. Even though this property is not inherited, anonymous block container boxes generated to establish the line box's inline formatting context (see [=block container=]) are ignored, and the value of the property that applies is the one on the non anonymous box. This can be seen in the “nested paragraph” part of example 7: even though the word “NESTED” is wrapped in an anonymous block container whose 'text-overflow' property has the initial value, it is ellipsed. Text can overflow for example when it is prevented from wrapping (e.g. due to> | fade | < > ]{1,2} Initial: clip Applies to: block containers Inherited: no Percentages: refer to the width of the line box Computed value: as specified, with lengths made absolute Animation type: by computed value type
white-space: nowrap
or a single word is too long to fit).
Values have the following meanings:
div {
font-family: monospace;
white-space: pre;
overflow: hidden;
width: 9ch;
text-overflow: ellipsis;
}
Sample HTML fragments, renderings, and your browser:
HTML | Reference rendering | Your Browser |
---|---|---|
<div>שלום 123456</div> | 123456 ם… | |
<div dir=rtl>שלום 123456</div> | …456 שלום |
div {
font-family: Helvetica, sans-serif;
line-height: 1.1;
width: 3.1em;
border: solid .1em black;
padding: 0.2em; margin:1em 0;
}
sample HTML fragments, renderings, and your browser:
HTML | sample rendering | your browser |
---|---|---|
|
CSS IS AWESOME, YES
| |
| ||
| ||
| ||
|
direction: rtl
)
block clips inline content on the left side,
thus would place a text-overflow ellipsis on the left
to represent that clipped content.
Issue: insert RTL example diagram here to illustrate note.
div.crawlbar {
text-overflow: ellipsis;
height: 2em;
overflow: scroll;
white-space: nowrap;
width: 15em;
border:1em solid black;
}
sample HTML fragment:
<div class="crawlbar">
CSS is awesome, especially when you can scroll
to see extra text instead of just
having it overlap other text by default.
</div>
demonstration of sample CSS and HTML:
text-overflow: ellipsis ellipsis
, demonstrated:
Name: block-ellipsis Value: none | auto | <This property allows inserting content into the last line box before a (forced or unforced) region break to indicate the continuity of truncated/interrupted content. It only affects line boxes contained directly by the block container itself, but as it inherits, will have an effect on descendants’ line boxes unless overridden. If the box contains no line box immediately preceding a region break, then this property has no effect. Note: See [[#fragmentation]] for a way to generate boxes with such a [=region break=]. ISSUE: Should this apply to other types of fragmentation breaks (e.g. pages, columns)? The inserted content is called the block overflow ellipsis. Values have the following meanings:> Initial: none Applies to: [=block containers=] Inherited: yes Percentages: N/A Computed value: specified value Animation type: discrete
Name: line-clamp Value: none | <The 'line-clamp' property is a shorthand for the 'max-lines', 'block-ellipsis', and 'continue' properties. Issue: For the time being, experimental implementations are encouraged to follow the full behavior defined by this shorthand and its longhands, but to only expose the shorthand to authors. This is in order to facilitate further tweaking, and in particular potential renaming, of the longhand properties and their values. It allows limiting the contents of a block container to the specified number of lines; remaining content is fragmented away and neither rendered nor measured. Optionally, it also allows inserting content into the last line box to indicate the continuity of truncated/interrupted content. The values have the following meaning:> <<'block-ellipsis'>>? Initial: none Percentages: N/A
+---------------------------------------+ | CHEESE IS ACTUALLY MADE OF MILK! | | Investigative reporters at the World | | Wide Web Press Corps have discovered | | the secret of cheese. Tracing through | | byzantine… (continued on next page) | +---------------------------------------+
Name: -webkit-line-clamp Value: none | <> Initial: none Percentages: N/A
Name: continue New Values: -webkit-discardLike 'line-clamp', '-webkit-line-clamp' is a shorthand of 'max-lines', 'continue', and 'block-ellipsis', except that: * its syntax is ''line-clamp/none'' | <
Name: max-lines Value: ''none'' | <This property has no effect on boxes that are not [=fragmentation containers=] that capture [=region breaks=]. Otherwise, if the value of 'max-lines' is not none, a region break is forced after its Nth descendant in-flow line box, where N is the specified value of 'max-lines'. Only lines boxes in the same Block Formatting Context are counted: the contents of descendants that establish independent formatting contexts are skipped over while counting line boxes. If fewer than N line boxes exist, then 'max-lines' introduces no region break.> Initial: ''none'' Applies to: block containers which are also [=fragmentation containers=] that capture [=region breaks=] Inherited: no Percentages: N/A Computed value: the keyword ''max-lines/none'' or an integer Animation type: by computed value type
#a { line-clamp: 5; } #b { line-clamp: 2; }
:
a: line 1 a: line 2 b: line 1 b: line 2… a: line 3…Sample rendering given
#a { line-clamp: 3; } #b { line-clamp: 2; }
:
a: line 1 a: line 2 b: line 1…Note that in the second case, the maximum of 2 lines set on element ''#b'' does not take effect, since a forced break is introduced before the second line of this element.
Name: continue Value: auto | discard Initial: ''continue/auto'' Applies to: [=block containers=] and [=multicol containers=] Inherited: no Percentages: N/A Computed value: specified keyword Animation type: discreteThe 'continue' property gives authors the ability to turn a box into a [=fragmentation container=] (see [[!CSS-BREAK-3]]) and to specify that content after the [=fragmentation break=] must be discarded. Issue: This property is meant to generalize and replace the
region-fragment
property from [[CSS-REGIONS-1]].
Once it is sufficiently stable in this specification,
region-fragment
should be removed from the regions specification in favor of this.
''continue: discard'' | ''continue: auto'' | |
---|---|---|
''overflow: visible'' | ![]() |
![]() |
''overflow: hidden'' | ![]() |
![]() |
In CSS Level 1 [[CSS1]], placing more content than would fit inside an element with a specified size was generally an authoring error. Doing so caused the content to extend outside the bounds of the element, which would likely cause that content to overlap with other elements.
CSS Level 2 [[CSS2]] introduced the 'overflow' property, which allows authors to have overflow be handled by scrolling, which means it is no longer an authoring error. It also allows authors to specify that overflow is handled by clipping, which makes sense when the author's intent is that the content not be shown. This was further refined in the CSS Overflow Module Level 3 [[CSS-OVERFLOW-3]].
However, scrolling is not the only way to present large amounts of content, and may even not be the optimal way. After all, the codex replaced the scroll as the common format for large written works because of its advantages.
This specification introduces a mechanism for Web pages to specify that an element of a page should handle overflow through pagination rather than through scrolling.
This specification also extends the concept of overflow in another direction. Instead of requiring that authors specify a single area into which the content of an element must flow, this specification allows authors to specify multiple fragments, each with their own dimensions and styles, so that the content of the element can flow from one to the next, using as many as needed to place the content without overflowing.
In both of these cases, implementations must break the content in the block-progression dimension. Implementations must do this is described in the CSS Fragmentation Module [[!CSS-BREAK-3]].
Name: continue New Values: overflow | paginate | fragments Initial: auto Applies to: block containers [[!CSS2]], flex containers [[!CSS3-FLEXBOX]], and grid containers [[!CSS3-GRID-LAYOUT]] Inherited: no Percentages: N/A Computed value: see below Animation type: discreteIssue: The naming of this property and its values is preliminary. This was initially proposed as "fragmentation: auto | none | break | clone | page" in https://lists.w3.org/Archives/Public/www-style/2015Jan/0357.html, and there is not yet wide agreement as to which naming is better. Issue: This property is meant to generalize and replace 'region-fragment'. Once it is sufficiently stable in this specification, 'region-fragment' should be removed from the regions specification in favor of this. Note: ''continue: fragments'' replaces "overflow:fragments" from earlier versions of this specification, while ''continue: paginate'' replaces "overflow: paged-x | paged-y | paged-x-controls | paged-y-controls"
@media (overflow-block: paged), (overflow-block: optional-paged) {
:root {
continue: paginate;
}
}
The current implementation of paginated overflow uses the overflow/overflow-x/overflow-y properties rather than the overflow-style property as proposed in the [[CSS3GCPM]] draft (which also matches the [[CSS3-MARQUEE]] proposal). or the 'continue' property as described here.
When the computed value of 'continue' for an element is ''continue/fragments'', and implementations would otherwise have created a box for the element, then implementations must create a sequence of fragment boxes for that element. (It is possible for an element with ''continue: fragments'' to generate only one fragment box. However, if an element's computed 'continue' is not ''continue/fragments'', then its box is not a fragment box.) Every fragment box is a fragmentation container, and any overflow that would cause that fragmentation container to fragment causes another fragment box created as a next sibling of the previous one. Or is it as though it's a next sibling of the element? Need to figure out exactly how this interacts with other box-level fixup. Additionally, if the fragment box is also a multi-column box (as defined in [[!css-multicol-1]] though it defines multi-column container) any content that would lead to the creation of overflow columns [[!css-multicol-1]] instead is flown into an additional fragment box. However, fragment boxes may themselves be broken (due to fragmentation in a fragmentation context outside of them, such as pages, columns, or other fragment boxes); such breaking leads to fragments of the same fragment box rather than multiple fragment boxes. (This matters because fragment boxes may be styled by their index; such breaking leads to multiple fragments of a fragment box with a single index. This design choice is so that breaking a fragment box across pages does not break the association of indices to particular pieces of content.) Should a forced break that breaks to an outer fragmentation context cause a new fragment of a single fragment box or a new fragment box? Should we find a term other than fragment box here to make this a little less confusing?
What if we want to be able to style the pieces of an element split within another type of fragmentation context? These rules prevent ever using ''::nth-fragment()'' for that, despite that the name seems the most logical name for such a feature.
|
In this example, the text in the
div is broken into a series of cards. These cards all have the same style. The presence of enough content to overflow one of the cards causes another one to be created. The second
card is created just like it's the next sibling of the first. |
|
The max-lines property allows
authors to use a larger font for the first few lines of an article. Without the max-lines property, authors
might have to use the 'height' property instead, but that would leave a slight gap if the author miscalculated how much height a given number of lines would occupy (which might be particularly hard if the author
didn't know what text would be filling the space, exactly what font would be used, or exactly which platform's font rendering would be used to display the font). |
We should specify that ''continue: fragments'' does not apply to at least some table parts, and perhaps other elements as well. We need to determine exactly which ones.
This specification needs to say which type of fragmentation context is created so that it's clear which values of the 'break-*' properties cause breaks within this context. We probably want ''break-*: region'' to apply.
This specification needs a processing model that will apply in cases where the layout containing the fragments has characteristics that use the intrinsic size of the fragments to change the amount of space available for them, such as [[CSS3-GRID-LAYOUT]]. There has already been some work on such a processing model in [[CSS-REGIONS-1]], and the work done on a model there, and the editors of that specification, should inform what happens in this specification.
The ::nth-fragment() pseudo-element is a pseudo-element that describes some of the fragment boxes generated by an element. The argument to the pseudo-element takes the same syntax as the argument to the :nth-child() pseudo-class defined in [[!SELECT]], and has the same meaning except that the number is relative to fragment boxes generated by the element instead of siblings of the element.
Selectors that allow addressing fragments by counting from the end rather than the start are intentionally not provided. Such selectors would interfere with determining the number of fragments.
Depending on future discussions, this ''::nth-fragment(an+b)'' syntax may be replaced with the new ''::fragment:nth(an+b)'' syntax.
Should this apply to continue:fragments only, or also to continue:paginate? (If it applies, then stricter property restrictions would be needed for continue:paginate.)
In the absence of rules with ''::nth-fragment()'' pseudo-elements, the computed style for each fragment box is the computed style for the element for which the fragment box was created. However, the style for a fragment box is also influenced by rules whose selector's subject [[!SELECT]] has an ''::nth-fragment()'' pseudo-element, if the 1-based number of the fragment box matches that ''::nth-fragment()'' pseudo-element and the selector (excluding the ''::nth-fragment()'' pseudo-element) matches the element generating the fragments.
When determining the style of the fragment box, these rules that match the fragment pseudo-element cascade together with the rules that match the element, with the fragment pseudo-element adding the specificity of a pseudo-class to the specificity calculation. Does this need to be specified in the cascading module as well?
|
In this
example, the text in the div is broken into a series of columns. The author probably intended the
text to fill two columns. But if it happens to fill three columns, the third column is still created. It just doesn't
have any fragment-specific styling because the author didn't give it any. |
Styling an ''::nth-fragment()'' pseudo-element with the 'continue' property does take effect; if a fragment box has a computed value of 'continue' other than ''fragments'' then that fragment box is the last fragment. However, overriding 'continue' on the first fragment does not cause the fragment box not to exist; whether there are fragment boxes at all is determined by the computed value of overflow for the element.
Styling an ''::nth-fragment()'' pseudo-element with the 'content' property has no effect; the computed value of 'content' for the fragment box remains the same as the computed value of content for the element.
Specifying ''display: none'' for a fragment box causes the fragment box with that index not to be generated. However, in terms of the indices used for matching ''::nth-fragment()'' pseudo-elements of later fragment boxes, it still counts as though it was generated. However, since it is not generated, it does not contain any content.
Specifying other values of 'display', 'position', or 'float' is permitted, but is not allowed to change the inner display type. (Since 'continue' only applies to block containers, flex containers, and grid containers). Need to specify exactly how this works
To match the model for other pseudo-elements where the pseudo-elements live inside their corresponding element, declarations in ''::nth-fragment()'' pseudo-elements override declarations in rules without the pseudo-element. The relative priority within such declarations is determined by normal cascading order (see [[!CSS2]]).
Styles specified on ''::nth-fragment()'' pseudo-elements do affect inheritance to content within the fragment box. In other words, the content within the fragment box must inherit from the fragment box's style (i.e., the pseudo-element style) rather than directly from the element. This means that elements split between fragment boxes may have different styles for different parts of the element.
This inheritance rule allows specifying styles indirectly (by using explicit ''inherit'' or using default inheritance on properties that don't apply to ''::first-letter'') that can't be specified directly (based on the rules in the next section). This is a problem. The restrictions that apply to styling inside fragments should also apply to inheritance from fragments.
|
The
font-size propertyspecified on the fragment is inherited into the descendants of the fragment.
This means that inherited properties can be used reliably on a fragment, as in this example. |
Should this apply to continue:fragments only, or also to continue:paginate?
The ''::nth-fragment()'' pseudo-element can also be used to style content inside of a fragment box. Unlike the ''::first-line'' and ''::first-letter'' pseudo-elements, the ''::nth-fragment()'' pseudo-element can be applied to parts of the selector other than the subject: in particular, it can match ancestors of the subject. However, the only CSS properties applied by rules with such selectors are those that apply to the ''::first-letter'' pseudo-element.
To be more precise, when a rule's selector has ''::nth-fragment()'' pseudo-elements attached to parts of the selector other than the subject, the declarations in that rule apply to a fragment (or pseudo-element thereof) when:
|
Name: scrollbar-gutter New Values: auto | [ [ stable | always ] && both-edges? && force? ] || match-parent Applies to: all elementsFor overlay scrollbars, the precise width of the scrollbar gutter, if present, is UA defined. However, it must not be 0, and it must not change based on user interactions with the page or the scrollbar even if the scrollbar itself changes, with the expectation that it covers the width of the overlay scrollbar in its widest form, to the extent that this is well defined. The new values of this property have the following meaning:
scrollbar-avoid: none | [self | content] && both-edges?
.
An interesting consideration is that this may alleviate the need for ''scrollbar-gutter: match-parent'',
as it seems that situations that would have been addressed by ''scrollbar-gutter: stable'' or ''scrollbar-gutter: always'' on the parent
and ''scrollbar-gutter: match-parent'' on the select children
could instead be addressed by leaving the parent as ''scrollbar-gutter: auto''
and using scrollbar-avoid: self
or scrollbar-avoid: content
on the relevant children.
parent.gutter - child.border - child.margin
,
and the gutter+border+margin is what collapses with the parent's gutter.
If the box with ''scrollbar-gutter/ match-parent'' is itself a [=scroll container=],
depending on the type of scrollbars,
on its 'overflow' property,
and on the other values of the 'scrollbar-gutter' property,
it may need additional gutter for its own scrollbars.
This comes in addition to the amount of gutter added for the sake of the ''scrollbar-gutter/match-parent'' value
and does not collapse with the parent's gutter.
'overflow' | 'scrollbar-gutter' | Classic scrollbars | Overlay scrollbars (whether overflowing or not) | |
---|---|---|---|---|
Overflowing | Not overflowing | |||
''overflow/scroll'' | ''scrollbar-gutter/auto'' | yes | yes | |
''scrollbar-gutter/stable'' | yes | yes | ||
''scrollbar-gutter/always'' | yes | yes | yes | |
''overflow/auto'' | ''scrollbar-gutter/auto'' | yes | ||
''scrollbar-gutter/stable'' | yes | yes | ||
''scrollbar-gutter/always'' | yes | yes | yes | |
''overflow/hidden'' | ''scrollbar-gutter/auto'' | |||
''scrollbar-gutter/stable'' | yes | yes | ||
''scrollbar-gutter/always'' | yes | yes | yes | |
''overflow/visible'', ''overflow/clip'' | ''scrollbar-gutter/auto'' | |||
''scrollbar-gutter/stable'' | if ''force'' | if ''force'' | ||
''scrollbar-gutter/always'' | if ''force'' | if ''force'' | if ''force'' |
Thanks especially to the feedback from Rossen Atanassov, Bert Bos, Tantek Çelik, John Daggett, fantasai, Daniel Glazman, Vincent Hardy, Håkon Wium Lie, Peter Linss, Robert O'Callahan, Florian Rivoal, Alan Stearns, Steve Zilles, and all the rest of the www-style community.