Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tailwindlabs/tailwindcss-line-clamp
A plugin that provides utilities for visually truncating text after a fixed number of lines.
https://github.com/tailwindlabs/tailwindcss-line-clamp
Last synced: 27 days ago
JSON representation
A plugin that provides utilities for visually truncating text after a fixed number of lines.
- Host: GitHub
- URL: https://github.com/tailwindlabs/tailwindcss-line-clamp
- Owner: tailwindlabs
- License: mit
- Created: 2021-01-06T19:09:34.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T17:16:16.000Z (8 months ago)
- Last Synced: 2024-10-04T08:39:47.693Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 661 KB
- Stars: 1,177
- Watchers: 13
- Forks: 35
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tailwindcss - Line Clamp - Provides utilities for visually truncating text after a fixed number of lines. (Plugins)
README
# @tailwindcss/line-clamp
A plugin that provides utilities for visually truncating text after a fixed number of lines.
> **Warning**
> As of Tailwind CSS v3.3 the `line-clamp` utilities are now included in the framework by default and this plugin is no longer required.## Installation
Install the plugin from npm:
```sh
npm install -D @tailwindcss/line-clamp
```Then add the plugin to your `tailwind.config.js` file:
```js
// tailwind.config.js
module.exports = {
theme: {
// ...
},
plugins: [
require('@tailwindcss/line-clamp'),
// ...
],
}
```## Usage
Use the `line-clamp-{n}` utilities to specify how many lines of text should be visible before truncating:
```html
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
```To remove any line-clamping, use `line-clamp-none`:
```html
Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
```> Note that the `line-clamp-{n}` set other properties like `display` and `overflow` in addition to `-webkit-line-clamp` which are not unset by `line-clamp-none`, so depending on what you are trying to achieve you may need to explicitly override those properties with utilities like `flex` or `overflow-visible` as well.
Utilities are for clamping text up to 6 lines are generated by default:
| Class | CSS |
| --- | --- |
| `line-clamp-1` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 1;` |
| `line-clamp-2` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 2;` |
| `line-clamp-3` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 3;` |
| `line-clamp-4` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 4;` |
| `line-clamp-5` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 5;` |
| `line-clamp-6` | `overflow: hidden;`
`display: -webkit-box;`
`-webkit-box-orient: vertical;`
`-webkit-line-clamp: 6;` |
| `line-clamp-none` | `-webkit-line-clamp: unset;` |## Configuration
You can configure which values and variants are generated by this plugin under the `lineClamp` key in your `tailwind.config.js` file:
```js
// tailwind.config.js
module.exports = {
theme: {
extend: {
lineClamp: {
7: '7',
8: '8',
9: '9',
10: '10',
}
}
},
variants: {
lineClamp: ['responsive', 'hover']
}
}
```