Skip to content

Commit cda4931

Browse files
authored
Switch to a single property
Remove the 'Combining behaviors' section as it is not supported in the initial version. Update the proposed CSS property name from 'text-grow' to 'text-fit' and adjust related values.
1 parent 1497456 commit cda4931

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

README.md

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ A long headline containing several words or a very long word might easily overfl
9898
<img src="images/shrinking-b.png" width="180">
9999

100100

101-
101+
<!-- Remove "Combining behaivor" section.
102+
We don't support it in the initial version.
102103
103104
### Combining behaviors
104105
Using both expanding and shrinking creates fluid headlines that always attempt to occupy 100% of their container width, adapting automatically whether the container gets wider or narrower. Creates responsive layouts where text scales naturally with the design.
@@ -127,7 +128,7 @@ Using both expanding and shrinking creates fluid headlines that always attempt t
127128
...
128129
```
129130
<img src="images/combine-d.png" width="426">
130-
131+
-->
131132

132133
### Fitting Captions and Pull Quotes
133134
Text accompanying images or used as pull quotes often needs to precisely fit the width of the related content block. 'Shrinking' can prevent overflow, while 'Expanding' can be used to ensure short captions don't look awkward in wide containers.
@@ -137,62 +138,65 @@ For certain stylistic layouts, ensuring paragraphs or short text blocks align pe
137138

138139
## [Potential Solution]
139140

140-
We'd like to introduce two CSS properties.
141+
We'd like to introduce a new CSS property.
141142

142143
- Name:
143-
'**`text-grow`**'
144+
'**`text-fit`**'
144145
- Value:
145-
`<fit-target> <fit-method>? <length>?`
146+
`<fit-type> <fit-target>? <scale-limit>?`
146147
- Initial:
147148
none
148149
- Applies to:
149150
text containers
150151

151-
* Name:
152-
'**`text-shrink`**'
153-
* Value:
154-
`<fit-target> <fit-method>? <length>?`
155-
* Initial:
156-
none
157-
* Applies to:
158-
text containers
152+
```
153+
<fit-type> = none | grow | shrink
154+
```
155+
- `grow`: Allow lines to fit the target container width by enlarging text.
156+
- `shrink`: Allow lines to fit the target container width by shrinking text.
157+
159158

160159
```
161-
<fit-target> = none | consistent | per-line
160+
<fit-target> = consistent | per-line | per-line-all
162161
```
163-
- `per-line`: Makes each line in the target container larger/smaller independently
164162
- `consistent`: Makes all lines in the target container larger/smaller by a scaling factor for the widest line.
163+
- `per-line`: Makes each line in the target container larger/smaller independently, except for the last line.
164+
- `per-line-all`: Make each line in the target container larger/smaller independently, including the last line.
165165

166+
<!--
166167
```
167168
<fit-method> = scale | scale-inline | font-size | letter-spacing | ...
168169
```
169170
- `scale`: Scale glyphs in the original font-size.
170171
- `scale-inline`: Scale glyphs in the original font-size only horizontally. It's similar to SVG [`lengthAdjust=spacingAndGlyphs`](https://svgwg.org/svg2-draft/text.html#TextElementLengthAdjustAttribute). This method doesn't change line height.
171172
- `font-size`: Update the font-size and re-compute glyphs.
172173
- `letter-spacing`: Adjust line width by letter-spacing. It's similar to SVG [`lengthAdjust=spacing`](https://svgwg.org/svg2-draft/text.html#TextElementLengthAdjustAttribute). This method doesn't change line height.
174+
-->
173175

174-
175-
```<length>```: maximum font-size for `text-grow`, minimum font-size for `text-shrink`.
176+
```
177+
<scale-limit> = <percentage>
178+
```
179+
The maximum scaling factor for `grow`, or the minimum scaling factor for `shrink`.
176180

177181

178182
### Examples
179183

180184
#### Expanding
181185

182186
```css
183-
text-grow: per-line;
187+
text-fit: grow per-line-all;
184188
```
185189
See [Use cases Expanding](#expanding) A.
186190
If a line width is narrower than the container width, line's font-size is increased so that the line width matches the container width. Even if a single font-size is used in the container, each line might have different font-sizes.
187191
If a line width is wider than the container width, the line is unchanged.
188192

189193
```css
190-
text-grow: per-line 30px;
194+
text-fit: grow per-line-all 200%;
191195
```
192-
Ditto. However the increased font-size is capped to 30px. So, lines might be narrower than the container width.
196+
Ditto. However the text will expand up to twice the original size. So, lines might be narrower than the container width.
193197

194198
```css
195-
text-grow: consistent;
199+
text-fit: grow consistent;
196200
```
197201
See [Use cases Expanding](#expanding) B.
198202
Compute a scaling factor so that the widest line in the container fits to the container width, and scale all lines in the container by the scaling factor.
@@ -201,24 +205,25 @@ If the widest line is wider than the container width, nothing happens.
201205
#### Shrinking
202206

203207
```css
204-
text-shrink: per-line;
208+
text-fit: shrink per-line-all;
205209
```
206210
See [Use cases Shrinking](#shrinking) A.
207211
If a line width is wider than the container width, line's font-size is decreased so that the line width matches the container width. Even if a single font-size is used in the container, each line might have different font-sizes.
208212
If a line width is narrower than the container width, the line is unchanged.
209213

210214
```css
211-
text-shrink: per-line 8px;
215+
text-fit: shrink per-line-all 50%;
212216
```
213-
Ditto. However the decreased font-size must not be less than 8px. So lines might be wider than the container width.
217+
Ditto. However the text will shrink down to half the original size. So lines might be wider than the container width.
214218

215219
```css
216-
text-shrink: consistent;
220+
text-fit: shrink consistent;
217221
```
218222
See [Use cases Shrinking](#shrinking) B.
219223
Compute a scaling factor so that the widest line in the container fits to the container width, and scale all lines in the container by the scaling factor.
220224
If the widest line is narrower than the container width, nothing happens.
221225

226+
<!--
222227
#### Combining behaviors
223228

224229
```css
@@ -254,7 +259,7 @@ text-align: justify;
254259
```
255260
See [Use cases Combining](#combining-behaviors-1) D.
256261
Lines narrower than the container width are justified, and lines wider than the container width are scaled horizontally.
257-
262+
-->
258263

259264
## Detailed design discussion
260265

@@ -267,17 +272,18 @@ Lines narrower than the container width are justified, and lines wider than the
267272
* How does this interact with properties with `<length>`.
268273
* Should the length be scaled or not? Depends on its units (`px`, `em`, `rem`, `%`, `vw`, `vh`, etc.)?
269274
* Property examples: `line-height`, `letter-spacing`, `word-spacing`, `text-indent`, `vertical-align`, ...
275+
<!--
270276
* The methods vaues `scale` and `font-size` that can be specified for `<fit-method>` can produce similar visual results. Through prototype implementation and discussion, we aim to decide whether to standardize both or remove one of them.
271277
* `scale` linearly scales up the glyph data obtained at the original font size for rendering. Consequently, the displayed glyph might differ from the ideal glyph intended for that size. However, since the glyph data retrieval process only happens once, it operates significantly faster.
272278
* `font-size` renders the ideal glyph for the displayed size. This process can be considerably slower because it necessitates trying out glyphs of various sizes.
279+
-->
273280
* How to find the best-fit font-size?
274281
There are cases where the line width becomes smaller even if the font-size is increased.
282+
<!--
275283
* `font-weight` or `font-width` for `<fit-method>`?
276284
They work well only with specific fonts, and they don't offer the flexibility to fit text to any width. So we don't apply them in the initial proposal.
277-
* Accessibility
278-
If an end-user tries to enlarge font size, UAs should not fit enlarged lines to the container width. Is minimum-font setting enough?
279-
* The user's minimum font size preference should be respected.
280-
* How to handle last lines if `text-grow:per-line` is specified. Should we widen them even if auto-wrapped?
285+
-->
286+
* Accessibility: See https://github.com/w3c/csswg-drafts/issues/12886.
281287
* Text decoration, emphasis marks, ruby annotations should work well.
282288
* Line's available width can depend on its block offset. e.g. `float` and `initial-letter`.
283289
* `text-align` should be applied after this feature. It will be applied only to narrow lines.

0 commit comments

Comments
 (0)