This section is not normative.
CSS layout has several different concepts of automatic sizing that are used in various layout calculations. This section defines some more precise terminology to help connect the layout behaviors of this spec to the calculations used in other modules, and some new keywords for the width and height properties to allow authors to assign elements the dimensions resulting from these size calculations.
1.1. Module interactions
This module extends the width, height, min-width, min-height, max-width, max-height, and column-width features defined in [CSS21] chapter 10 and in [CSS3COL]
This specification follows the CSS property definition conventions 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: for example [CSS3COLOR], when combined with this module, expands the definition of the <color> value type as used in this specification.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.
- A one- or two-dimensional measurement: a block size and/or inline size; alternatively a width and/or height.
- definite size
- A size that can be determined without measuring content; that is, a <length>, a size of the initial containing block, or a <percentage> that is resolved against a definite size. Additionally, the size of the containing block of an absolutely positioned element is always definite with respect to that element.
- indefinite size
- A size that is not definite. An indefinite available size is essentially infinite.
- available size
- The space into which a box is laid out. Unless otherwise specified, this is either a measurement of its containing block (if that is definite) or an infinite size (when it is indefinite). An available size can alternatively be either a min-content constraint or a max-content constraint.
- fill-available fit
The fill-available fit into a given size
is that size,
minus the element’s computed margins (not collapsed, treating auto as zero),
border, and padding in the given dimension.
Note: This is the formula used to calculate the auto widths of non-replaced blocks in normal flow in CSS2.1§10.3.3.
- fallback size
- Some sizing algorithms do not work well with an infinite size. In these cases, the fallback size is used instead. Unless otherwise specified, this is the size of the initial containing block.
2.1. Auto Box Sizes
A box’s “ideal” size in a given axis when given infinite available space. Usually this is the smallest size the box could take in that axis while still fitting around its contents, i.e. minimizing unfilled space while avoiding overflow.
The box’s “ideal” size in the inline axis. Usually the narrowest inline size it could take while fitting around its contents if none of the soft wrap opportunities within the box were taken. (See §4 Intrinsic Size Determination.)
The narrowest inline size a box could take that doesn’t lead to inline-dimension overflow that could be avoided by choosing a larger inline size. Roughly, the inline size that would fit around its contents if all soft wrap opportunities within the box were taken.
Equivalent to the max-content block size.
Or should this be the minimum between allowed break points? It might make sense in multi-col contexts to have min-content and max-content block-sizes be different, even if they are the same elsewhere.
2.2. Intrinsic Size Contributions
- max-content contribution
- The size that a box contributes to its containing block’s max-content size.
- min-content contribution
- The size that a box contributes to its containing block’s min-content size.
2.3. Intrinsic Size Constraints
- max-content constraint
- A sizing constraint imposed by the box’s containing block that causes it to produce its max-content contribution.
- min-content constraint
- A sizing constraint imposed by the box’s containing block that causes it to produce its min-content contribution.
3. New Sizing Keywords
3.1. New Keywords for width and height
|Name:||width, min-width, max-width, height, min-height, max-height|
|New values:||fill | max-content | min-content | fit-content|
There are four types of automatically-determined sizes in CSS (which are represented in the width and height properties by the keywords defined above):
- Use the fill-available inline size or fill-available block size, as appropriate to the writing mode.
- Use the max-content inline size or max-content block size, as appropriate to the writing mode.
- Use the min-content inline size or min-content block size, as appropriate to the writing mode.
- Use the fit-content inline size or fit-content block size, as appropriate to the writing mode.
- repudiate-floats Less stupid name?
In the inline axis,
use the larger of the min-content inline size,
and the fill-available inline size minus the size of any non-descendant floats in the same formatting context.
(This is similar to the behavior of a box that establishes a formatting context next to a float.)
In the block axis,
this is identical to auto.
Does this value work? Is it needed? Feedback from dbaron
Right now all of these except fill mean the same thing for block-sizes. This may or may not be ideal.
If the inline-size is auto, we could have min-content block-size imply a max-content inline-size, and vice versa.
Note that percentages resolved against the intrinsic sizes (max-content, min-content, fit-content, repudiate-floats) will compute to auto, as defined by CSS 2.1. [CSS21]
3.2. Containing Floats
- Equivalent to min-content except that when applied to the block-size of a block box it forces the inner block-size to be large enough to contain the margin boxes of any floats that originate inside the block and that participate in the same block formatting context as the block’s immediate contents.
3.3. Column Sizing Keywords
|New values:||fill | max-content | min-content | fit-content|
When used as values for column-width, the new keywords specify the optimal column width:
- Specifies the optimal column width as the fill-available inline size of the multi-column element.
- Specifies the optimal column width as the max-content inline size of the multi-column element’s contents.
- Specifies the optimal column width as the min-content inline size of the multi-column element’s contents.
- Specifies the optimal column width as
min(max-content inline size, max(min-content inline size, fill-available inline size)).
4. Intrinsic Size Determination
Intrinsic sizing determines sizes based on the contents of an element, without regard for its context.
4.1. Intrinsic Sizes of Replaced Elements
For replaced elements, the min-content size and max-content size are equivalent and correspond to the appropriate dimension of the concrete object size returned by the default sizing algorithm [CSS3-IMAGES] of the element, calculated with an unconstrained specified size.
The min-content contribution and max-content contribution in each axis is the element’s specified outer size in that axis, if definite; otherwise, they are the min-content size, as specified above, plus the element’s margin/border/padding in that axis, clamped by the element’s min and max size properties in that axis.
4.2. Intrinsic Sizes of Non-Replaced Inlines
The min-content inline size of an inline box is the length of the largest unbreakable sequence of inline content. The min-content inline-size contribution of an inline box is its min-content inline size, plus any inline-axis margin, border, and padding adjacent to that sequence.
The max-content inline size of an inline box is the length of the largest sequence of inline content on a single line when only forced line breaks are taken. The max-content inline-size contribution of an inline box is its max-content inline size, plus any inline-axis margin, border, and padding adjacent to that sequence.
The min-content block size, max-content block size, min-content block-size contribution, and max-content block-size contribution of an inline box are the distance from the head edge of the first line box to the foot edge of the last line box on which the inline appears.
4.3. Intrinsic Sizes of Non-Replaced Blocks
The min-content inline size of a block container box is the largest min-content inline-size contribution of its in-flow or floated children.
The max-content inline size of a block container box is the inline-size of the box after layout, if all children are sized under a max-content constraint.
If the computed inline-size of a block-level box is min-content, max-content, or a definite size, its min-content inline-size contribution is that size plus any inline-axis margin, border, and padding. Otherwise, if the computed inline-size of the block is fit-content, auto, or fill, its min-content inline-size contribution is its min-content inline size plus any inline-axis margin, border, and padding.
If the computed inline-size of a block-level box is min-content, max-content, or a definite size, its max-content inline-size contribution is that size plus any inline-axis margin, border, and padding. Otherwise, if the computed inline-size of the block is fit-content, auto, or fill, its max-content inline-size contribution is its max-content inline size plus any inline-axis margin, border, and padding.
The min-content block size and max-content block size of a block container box is the content block-size as defined (for horizontal writing modes) in CSS2.1§10.6.3 and CSS2.1§17.5.3 for elements with height: auto, and analogously for vertical writing modes.
The min-content block-size contribution and max-content block-size contribution of a block-level box is the block-size of the block after layout, plus any block-axis margin, border, and padding.
Need to handle floats. See Greg’s issue and dbaron’s response.
4.4. Intrinsic Sizes in Table Layout
4.5. Intrinsic Sizes in Multi-column Layout
4.5.1. Min-content Sizes in Multi-column Layout
The min-content inline size of a multi-column element with a computed column-width not auto is the smaller of its column-width and the largest min-content inline-size contribution of its contents.
The min-content inline size of a multi-column element with a computed column-width of auto is the largest min-content inline-size contribution of its contents multiplied by its column-count (treating auto as 1).
4.5.2. Max-content Sizes in Unconstrained-height Multi-column Layout
The max-content inline size of a multi-column element with unrestrained column heights and a computed column-count not auto is its column-count multiplied by the larger of its column-width (treating auto as zero) and the largest min-content inline-size contribution of its contents.
Note that the contents of the multi-column element can still grow to be wider and shorter if the resulting column width is still smaller than the largest max-content inline-size contribution of its contents.
The max-content inline size of a multi-column element with unrestrained column heights and a computed column-count of auto is its column-width multiplied by the number of columns obtained by taking all allowed column breaks [CSS3-BREAK].
4.5.3. Max-content Sizes in Constrained-height Multi-column Layout
The max-content inline size of a multi-column element with restrained-height columns (i.e. a specified height or max-height, or whichever properties map to the block size of the element) is the inline size that would exactly include all of its columns. It may be approximated by:
- Laying out the element with column-spanning elements given display: none, and taking a inline-size that includes all the columns.
- Laying out all of the column-spanning elements into that resulting inline-size, and taking the resulting block-size.
- Subtracting that resulting block-size from the specified restraint, laying out the element without column-spanning elements again into this adjusted block-size, and taking the inline-size of all its columns as its max-content inline size.
or by some more accurate method.
This approximation can result in some slack, but avoids overflow in the most common cases, where the balanced height of the columns above spanning elements are approximately equal.
In the common case of no column-spanning elements, this approximation collapses to simply doing a layout, and measuring the resulting columns.
5. Extrinsic Size Determination
Extrinsic sizing determines sizes based on the context of an element, without regard for its contents.
5.1. Fill-available Sizing
The inner fill-available inline size of a box is…
- If the box is the root or is absolutely-positioned, the inline-size of its containing block, else
max(min-content inline size|0, min(max-content inline size|infinity, inline size|fill-available inline size))where the sizes are inner inline-sizes of the element establishing the box’s containing block, and where the first value is used if it is definite and the second value otherwise.
…less the box’s inline-axis margins (after any margin collapsing, and treating auto margins as zero), borders, and padding.
The fill-available block size of a box is defined analogously, but in the other dimension.
This definition might end up skipping further up the ancestor chain than we’d like in some cases. Example. Maybe it should stop at each formatting root, or something similar?
5.2. Percentage Sizing
Write something useful here. Like about when to fall back to auto or whatever.
In order to prevent cyclic sizing, the auto value of min-height and max-height does not factor into the percentage size resolution of the box’s contents. For example, a percentage-height block whose flex item parent has height: 120em; min-height: auto will size itself against height: 120em regardless of the impact that min-height might have on the used size of the flex item.
Changes since the September 2012 Working Draft include:
- Hooked up intrinsic sizes of replaced elements to the default sizing algorithm in [CSS3-IMAGES].
- Specified that extrinsic sizing treates auto margins as zero.
- Clarified definition of available size.
- Specified that percentages resolved against an intrinsic size of the parent computes falls back to auto sizing.
- Fixed bad wording wrt containing blocks in fill-available inline size definition, and specified that it is calculated after margin collapsing.
- Specified that an absolutely-positioned box’s containing block is always considered definite.
- Improved section on intrinsic sizing of multi-column elements.
- Cleaned up some terminology (“min-size” to “min-content size”, “measure” to “inline-size, “extent” to “block-size”).
Special thanks go to Aaron Gustafson, L. David Baron for their contributions to this module.