相关文章推荐
卖萌的数据线  ·  DEFY - All Watches - ...·  1 年前    · 
卖萌的数据线  ·  Home | DEFY·  1 年前    · 
卖萌的数据线  ·  Defy Definition & ...·  1 年前    · 

Quick reference

Class
Properties
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 overflow : visible ; display : block ; -webkit-box-orient : horizontal ; -webkit-line-clamp : none ;

Basic usage

Truncating multi-line text

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>
    <img src="..." />
    Lindsay Walton
  </div>
</article>

Undoing line clamping

Use line-clamp-none to undo a previously applied line clamp utility.

<p class="line-clamp-3 lg:line-clamp-none">
  <!-- ... -->

Applying conditionally

Hover, focus, and other states

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.

<p class="line-clamp-3 hover:line-clamp-4">
  <!-- ... -->

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

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.

<p class="line-clamp-3 md:line-clamp-4">
  <!-- ... -->

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.

Using custom values

Customizing your theme

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.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      lineClamp: {
        7: '7',