You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: README.md
+36-30Lines changed: 36 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,8 @@ A long headline containing several words or a very long word might easily overfl
98
98
<imgsrc="images/shrinking-b.png"width="180">
99
99
100
100
101
-
101
+
<!-- Remove "Combining behaivor" section.
102
+
We don't support it in the initial version.
102
103
103
104
### Combining behaviors
104
105
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
127
128
...
128
129
```
129
130
<img src="images/combine-d.png" width="426">
130
-
131
+
-->
131
132
132
133
### Fitting Captions and Pull Quotes
133
134
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
137
138
138
139
## [Potential Solution]
139
140
140
-
We'd like to introduce two CSS properties.
141
+
We'd like to introduce a new CSS property.
141
142
142
143
- Name:
143
-
'**`text-grow`**'
144
+
'**`text-fit`**'
144
145
- Value:
145
-
`<fit-target> <fit-method>? <length>?`
146
+
`<fit-type> <fit-target>? <scale-limit>?`
146
147
- Initial:
147
148
none
148
149
- Applies to:
149
150
text containers
150
151
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.
- `scale`: Scale glyphs in the original font-size.
170
171
- `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.
171
172
- `font-size`: Update the font-size and re-compute glyphs.
172
173
- `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
+
-->
173
175
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`.
176
180
177
181
178
182
### Examples
179
183
180
184
#### Expanding
181
185
182
186
```css
183
-
text-grow: per-line;
187
+
text-fit: grow per-line-all;
184
188
```
185
189
See [Use cases Expanding](#expanding) A.
186
190
If aline width is narrower than the container width, line'sfont-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.
187
191
If aline width is wider than the container width, the line is unchanged.
188
192
189
193
```css
190
-
text-grow: per-line 30px;
194
+
text-fit: grow per-line-all 200%;
191
195
```
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.
193
197
194
198
```css
195
-
text-grow: consistent;
199
+
text-fit: grow consistent;
196
200
```
197
201
See [Use cases Expanding](#expanding) B.
198
202
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.
201
205
#### Shrinking
202
206
203
207
```css
204
-
text-shrink: per-line;
208
+
text-fit: shrink per-line-all;
205
209
```
206
210
See [Use cases Shrinking](#shrinking) A.
207
211
If aline width is wider than the container width, line'sfont-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.
208
212
If aline width is narrower than the container width, the line is unchanged.
209
213
210
214
```css
211
-
text-shrink: per-line 8px;
215
+
text-fit: shrink per-line-all 50%;
212
216
```
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.
214
218
215
219
```css
216
-
text-shrink: consistent;
220
+
text-fit: shrink consistent;
217
221
```
218
222
See [Use cases Shrinking](#shrinking) B.
219
223
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.
220
224
If the widest line is narrower than the container width, nothing happens.
221
225
226
+
<!--
222
227
#### Combining behaviors
223
228
224
229
```css
@@ -254,7 +259,7 @@ text-align: justify;
254
259
```
255
260
See [Use cases Combining](#combining-behaviors-1) D.
256
261
Lines narrower than the container width are justified, and lines wider than the container width are scaled horizontally.
257
-
262
+
-->
258
263
259
264
## Detailed design discussion
260
265
@@ -267,17 +272,18 @@ Lines narrower than the container width are justified, and lines wider than the
267
272
* How does this interact with properties with `<length>`.
268
273
* Should the length be scaled or not? Depends on its units (`px`, `em`, `rem`, `%`, `vw`, `vh`, etc.)?
* 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.
271
277
* `scale` linearly scales up the glyphdata 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 glyphdata retrieval process only happens once, it operates significantly faster.
272
278
* `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
+
-->
273
280
* How to find the best-fitfont-size?
274
281
There are cases where the line width becomes smaller even if the font-size is increased.
282
+
<!--
275
283
* `font-weight` or `font-width` for `<fit-method>`?
276
284
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.
281
287
*Text decoration, emphasis marks, ruby annotations should work well.
282
288
* Line's available width can depend on its block offset. e.g. `float` and `initial-letter`.
283
289
* `text-align` should be applied after this feature. It will be applied only to narrow lines.
0 commit comments