Title: CSS Intrinsic & Extrinsic Sizing Module Level 4 Shortname: css-sizing Level: 4 Status: ED Warning: not ready Work Status: Exploring Group: csswg ED: https://drafts.csswg.org/css-sizing TR: https://www.w3.org/TR/css-sizing/ Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199 Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400 Editor: Jen Simmons, Mozilla, http://jensimmons.com/ Previous version: https://www.w3.org/TR/2012/WD-css3-sizing-20120927/ Abstract: This is a delta spec over CSS Sizing Level 3. Ignored Terms: block-level box
spec:css-display-3; type:dfn; text:box spec:css2; type: property text: min-width text: min-height text: max-width text: max-height
This module extends the 'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', and 'column-width' features defined in [[!CSS2]] chapter 10 and in [[!CSS3COL]]
Name: aspect-ratio Value: auto | <This property sets an intrinsic aspect ratio for the box, which will be used in the calculation of ''height/auto'' sizes and some other layout functions. The box will essentially size the same as a replaced element with an intrinsic aspect ratio, see e.g. CSS2§10.> Initial: auto Inherited: no Applies to: all elements except inline boxes and internal ruby or table boxes Computed value: specified keyword or a pair of numbers
ul {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(12em, 1fr));
}
li {
aspect-ratio: 1/1;
overflow: auto;
}
width and height attributes
to set the 'aspect-ratio' property,
giving the iframe an aspect ratio to use for sizing
so that it behaves exactly like an image with that aspect ratio.
<iframe src="https://www.youtube.com/embed/0Gr1XSyxZy0" width=560 height=315>
@supports (aspect-ratio: attr(width px) / 1) {
iframe {
aspect-ratio: attr(width px) / attr(height px);
width: 100%;
height: auto;
}
}
ISSUE: Can we just slip this 'aspect-ratio' rule
into the UA default style sheet for images,
so that they have an aspect ratio while they load?
This would avoid the need for extra reflows after loading.
width: auto; min-height: min-content; aspect-ratio: 1/1;using the aspect ratio to resolve the width would require knowing the min-content height of the element. Since for a non-replaced element, this value is not known until the width is resolved, we assume the 'min-height' value is zero while resolving the width. Then, once the width is known, we resolve the height, taking into account the ''height/min-content'' minimum.
div {
aspect-ratio: 1/1;
min-height: max-content;
/* 'width' and 'height' both default to 'auto' */
}
+----------+ +----------+ +----------+ | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | | | ~~~ | | ~~~~~~~~ | +----------+ +----------+ | ~~~~~~~~ | | ~~~~~~ | +----------+
Name: min-width, min-height, max-width, max-height New Values: <The <> Computed value: ''tr'' dimension value
div {
min-height: 1tr;
}
+----------+ +----------+ +----------+ | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~ | | ~~~~~~~~ | | ~~~~~~~~ | | | | ~~~ | | ~~~~~~~~ | +----------+ +----------+ | ~~~~~~~~ | | ~~~~~~ | +----------+
Intrinsic sizing determines sizes based on the contents of an element, without regard for its context.
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.
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.
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 ''width/min-content'', ''width/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 ''width/fit-content'', ''width/auto'', or ''width/stretch'', 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 ''width/min-content'', ''width/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 ''width/fit-content'', ''width/auto'', or ''width/stretch'', 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. Issue: Need to handle floats. See Greg's issue and dbaron's response.
¯\_(ツ)_/¯
The min-content inline size of a multi-column container with a computed 'column-width' not ''column-width/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 container with a computed 'column-width' of ''column-width/auto'' is the largest min-content inline-size contribution of its contents multiplied by its 'column-count' (treating ''column-count/auto'' as ''1''), plus its 'column-gap' multiplied by 'column-count' minus 1.
The max-content inline size of a multi-column container with unrestrained column heights and a computed 'column-count' not ''column-count/auto'' is its 'column-count' multiplied by the larger of its 'column-width' (treating ''column-width/auto'' as zero) and the largest min-content inline-size contribution of its contents, plus its 'column-gap' multiplied by 'column-count' minus 1.
Note that the contents of the multi-column container 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 container with unrestrained column heights and a computed 'column-count' of ''column-count/auto'' is its 'column-width' multiplied by the number of columns obtained by taking all allowed column breaks [[CSS3-BREAK]], plus its 'column-gap' multiplied by that same number of columns minus 1.
The max-content inline size of a multi-column container 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:
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.
Changes since the September 2012 Working Draft include:
fill keyword to stretch-fit.
Special thanks go to Aaron Gustafson, L. David Baron for their contributions to this module.