Property truncates text at a specific number of lines

Philip is freelancer

If you feel the content is useful. Thank for me with a coffee ๐Ÿ˜Š

December 28, 2021 03:18 am

Brizycloud does not allow automatic excerpt generation like in wordpress. Adding them by hand causes different paragraph lengths and ugly blog layout. Fix it with a little simple css, too long text will be automatically collapsed +...

The -webkit-line-clamp CSS property allows limiting of the contents of a block container to the specified number of lines. It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical. In most cases you will also want to set overflow to hidden, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines. When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.

-webkit-line-clamp

The -webkit-line-clamp CSS property allows limiting of the contents of a block container to the specified number of lines.

It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical.

In most cases you will also want to set overflow to hidden, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines.

When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.

CODE

.yourclass p {

-webkit-line-clamp: 5;

display: -webkit-box!important;

-webkit-box-orient: vertical;

overflow: hidden;

}

*(5)Change the desired value

Demo


If you feel the content is useful. Thank for me with a coffee ๐Ÿ˜Š