Use the line-clamp-* utilities to truncate a block of text after a specific number of lines.
Boost your conversion rate
Nulla dolor velit adipisicing duis excepteur esse in duis nostrud occaecat mollit incididunt deserunt sunt. Ut ut sunt laborum ex occaecat eu tempor labore enim adipisicing minim ad. Est in quis eu dolore occaecat excepteur fugiat dolore nisi aliqua fugiat enim ut cillum. Labore enim duis nostrud eu. Est ut eiusmod consequat irure quis deserunt ex. Enim laboris dolor magna pariatur. Dolor et ad sint voluptate sunt elit mollit officia ad enim sit consectetur enim.
Lindsay Walton
<article>
<time>Mar 10, 2020</time>
<h2>Boost your conversion rate</h2>
<p class="line-clamp-3">Nulla dolor velit adipisicing duis excepteur esse in duis nostrud occaecat mollit incididunt deserunt sunt. Ut ut sunt laborum ex occaecat eu tempor labore enim adipisicing minim ad. Est in quis eu dolore occaecat excepteur fugiat dolore nisi aliqua fugiat enim ut cillum. Labore enim duis nostrud eu. Est ut eiusmod consequat irure quis deserunt ex. Enim laboris dolor magna pariatur. Dolor et ad sint voluptate sunt elit mollit officia ad enim sit consectetur enim.</p>
<div>
<img src="..." />
Lindsay Walton
</div>
</article>
Undoing line clamping
Use line-clamp-none to undo a previously applied line clamp utility.
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:line-clamp-4 to only apply the line-clamp-4 utility on hover.
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:line-clamp-4 to apply the line-clamp-4 utility at only medium screen sizes and above.
By default, Tailwind provides the six line-clamp utilities. You can customize these values by editing theme.lineClamp or theme.extend.lineClamp in your tailwind.config.js file.
Learn more about customizing the default theme in the theme customization documentation.
Arbitrary values
If you need to use a one-off line-clamp value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<p class="line-clamp-[7]">
<!-- ... -->
</p>
Learn more about arbitrary value support in the arbitrary values documentation.
发布评论