Title: CSS Step Size Shortname: css-snap-size Level: 1 Group: CSSWG Status: ED Work Status: exploring Editor: Koji Ishii, Google, kojiishi@gmail.com ED: https://drafts.csswg.org/css-snap-size/ Abstract: This module contains CSS features for aligning content size to multiple of unit size.
spec:css21; type:property; text:max-height spec:css21; type:property; text:max-width spec:css21; type:property; text:min-widthIntroduction {#intro} ===================== This specification provides features to control sizes of CSS objects according to the rules desired by use cases. Controlling sizes of CSS objects to be multiple of a unit is desired in many cases. This level of the specification focuses on following cases. * Adjust heights of line boxes to the multiple of the specified unit. * Adjust widths of block-level boxes to the multiple of the specified unit. By controlling heights of line boxes, lines of text in different fonts can create consistent visuals to help readability. Also by stacking such line boxes, authors can align lines across columns, pages, scroll-snapped blocks, or multiple blocks placed absolutely, to produce vertical rhythm. Controlling widths of block-level boxes to the multiple of the specified unit gives the ability to control a block so that it can fit mono-space characters without remainders. One of the use cases this feature addresses is better readability of East Asian documents. In Han ideographic-based scripts such as Chinese or Japanese, most characters have 1em advance, and due to that nature, most such documents are justified. Adjusting widths of block-level boxes to the multiple of 1em helps to minimize cases where justification needs to expand spacing. Adjusting Line Box Heights: the 'line-height-step' property {#line-height-step} ===============================================================================
Name: line-height-step Value: <Values have the following meanings:> < >? Initial: 0px Applies to: block containers Inherited: yes Animatable: no Percentages: N/A Media: visual Computed Value: the absolute length for length, others as specified
Rounding up the computed line box height.
:root {
--my-body-font-size: 12pt;
--my-grid: 18pt;
font-size: var(--my-body-font-size);
line-height-step: var(--my-grid);
}
h1 {
font-size: calc(1.618 * var(--my-body-font-size));
margin-top: calc(2 * var(--my-grid));
}
p {
margin: 0;
}
The line box in <h1> does not fit into one step unit
and thus occupies two,
but it is still centered within the two step unit.
:root {
line-height-step: 20pt 70;
}
The baseline of the line box is pushed down
to the closest step baseline position
by adding the space-over.
<h1> is as tall as
its baseline being lower than the second step baseline position
that it is pushed down to the third step baseline position.
<h2> to inline-blocks.
:root {
line-height-step: 18pt;
}
h2 {
display: inline-block;
width: 100%;
line-height-step: 0;
line-height: 1.2;
}
When an <h2> is long enough to wrap,
text inside the <h2> uses ''line-height: 1.2'', while
the height of the <h2> block is rounded up
to the multiple of ''18pt''.
See a sample in action.
Name: inline-size-step Value: <Non-negative <> Initial: 0px Applies to: all elements but non-replaced inline elements, table rows, and row groups Inherited: no Animatable: no Percentages: N/A Media: visual Computed Value: the absolute length
<article> elements
and blocks with bodytext class
are justified,
but the expansion occurs
only when there are non-CJK characters in the line
because their logical widths are
adjusted to the multiple of 1em.
article, .bodytext {
font-size: 12pt;
text-align: justify;
inline-size-step: 1em;
}