2019-07-30 02:56:17 +03:00
|
|
|
---
|
|
|
|
title: Truncate
|
|
|
|
path: components/truncate
|
|
|
|
status: Stable
|
2021-03-22 08:34:44 +03:00
|
|
|
source: 'https://github.com/primer/css/tree/main/src/truncate'
|
2019-07-30 02:56:17 +03:00
|
|
|
bundle: truncate
|
|
|
|
---
|
|
|
|
|
2020-12-09 13:36:11 +03:00
|
|
|
The `css-truncate` class will shorten text with an ellipsis.
|
2019-07-30 02:56:17 +03:00
|
|
|
|
2019-11-07 11:05:21 +03:00
|
|
|
## Truncate overflow
|
|
|
|
|
2019-11-08 03:55:44 +03:00
|
|
|
Combine the `css-truncate` and `css-truncate-overflow` classes to prevent text that overflows from wrapping.
|
2019-11-07 11:05:21 +03:00
|
|
|
|
|
|
|
```html live
|
|
|
|
<div class="col-3">
|
2020-12-09 13:36:11 +03:00
|
|
|
<div class="css-truncate css-truncate-overflow border p-3">
|
2019-11-07 11:05:21 +03:00
|
|
|
branch-name-that-is-really-long
|
|
|
|
</div>
|
|
|
|
<div class="border p-3 mt-3">
|
|
|
|
branch-name-that-is-really-long
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Truncate target
|
|
|
|
|
2019-11-08 03:55:44 +03:00
|
|
|
Combine the `css-truncate` and `css-truncate-target` classes for inline (or inline-block) elements with a fixed maximum width (default: `125px`).
|
2019-11-07 11:05:21 +03:00
|
|
|
|
|
|
|
```html live
|
|
|
|
Some text with a
|
2020-12-09 13:36:11 +03:00
|
|
|
<strong class="css-truncate css-truncate-target">
|
2019-11-07 11:05:21 +03:00
|
|
|
branch-name-that-is-really-long
|
|
|
|
</strong>
|
|
|
|
```
|
|
|
|
|
2019-11-08 03:55:44 +03:00
|
|
|
You can override the maximum width of the truncated text with an inline `style` attribute:
|
2019-11-07 11:05:21 +03:00
|
|
|
|
|
|
|
```html live
|
|
|
|
Some text with a
|
2020-12-09 13:36:11 +03:00
|
|
|
<strong class="css-truncate css-truncate-target" style="max-width: 180px">
|
2019-11-07 11:05:21 +03:00
|
|
|
branch-name-that-is-really-long
|
|
|
|
</strong>
|
2019-07-30 02:56:17 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
You can reveal the entire string on hover with the addition of `.expandable`.
|
|
|
|
|
2019-11-07 11:05:21 +03:00
|
|
|
```html live
|
|
|
|
Some text with a
|
2020-12-09 13:36:11 +03:00
|
|
|
<strong class="css-truncate css-truncate-target expandable">
|
2019-11-07 11:05:21 +03:00
|
|
|
branch-name-that-is-really-long
|
|
|
|
</strong>
|
2019-07-30 02:56:17 +03:00
|
|
|
```
|