|
| 1 | +# <text-overflow> |
| 2 | + |
| 3 | +The `<text-overflow>` CSS type sets how Textual wraps text. |
| 4 | + |
| 5 | +## Syntax |
| 6 | + |
| 7 | +The [`<text-overflow>`](./text_overflow.md) type can take any of the following values: |
| 8 | + |
| 9 | +| Value | Description | |
| 10 | +| ---------- | ----------------------------------------------------------------------------------- | |
| 11 | +| `clip` | Overflowing text will be clipped (the overflow portion is removed from the output). | |
| 12 | +| `fold` | Overflowing text will fold on to the next line. | |
| 13 | +| `ellipsis` | Overflowing text will be truncate and the last character replaced with an ellipsis. | |
| 14 | + |
| 15 | +## Examples |
| 16 | + |
| 17 | +In the following example we show the output of each of the values of `text_overflow`. |
| 18 | + |
| 19 | +The widgets all have [text wrapping][`text-wrap`](./text_wrap.md) disabled. |
| 20 | +Since the string is longer than the width, it will overflow. |
| 21 | + |
| 22 | +In the first (top) widget, "text-overflow" is set to "clip" which clips any text that is overflowing, resulting in a single line. |
| 23 | + |
| 24 | +In the second widget, "text-overflow" is set to "fold", which causes the overflowing text to *fold* on to the next line. |
| 25 | +When text folds like this, it won't respect word boundaries--so you may get words broken across lines. |
| 26 | + |
| 27 | +In the third widget, "text-overflow" is set to "ellipsis", which is similar to "clip", but with the last character set to an ellipsis. |
| 28 | +This option is useful to indicate to the user that there may be more text. |
| 29 | + |
| 30 | +=== "Output" |
| 31 | + |
| 32 | + ```{.textual path="docs/examples/styles/text_overflow.py"} |
| 33 | + ``` |
| 34 | + |
| 35 | +=== "text_overflow.py" |
| 36 | + |
| 37 | + ```py |
| 38 | + --8<-- "docs/examples/styles/text_overflow.py" |
| 39 | + ``` |
| 40 | + |
| 41 | +=== "text_overflow.tcss" |
| 42 | + |
| 43 | + ```css |
| 44 | + --8<-- "docs/examples/styles/text_overflow.tcss" |
| 45 | + ``` |
| 46 | + |
| 47 | + |
| 48 | +### CSS |
| 49 | + |
| 50 | +```css |
| 51 | +#widget { |
| 52 | + text-overflow: ellipsis; |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Python |
| 57 | + |
| 58 | +```py |
| 59 | +widget.styles.text_overflow = "ellipsis" |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | +## See also |
| 64 | + |
| 65 | + - [`text-wrap`](./text_wrap.md) is used to control wrapping. |
0 commit comments