Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure CSS Ellipsis For Three or More Lines of Text

Is there a CSS-only way (no JavaScript/jQuery) to only show the first two lines and, if there are three or more lines, hide the extra lines and show an ellipsis?

For example, how can I take this fiddle:

http://jsfiddle.net/0yyr3e63/

...and make it look like this?

Lorem Ipsum Dolor
Sit Amet Consectetur

Ut Enim Ad Minim
Veniam Quis Nostrud...

Duis Aute Irure
Dolor In...

Thanks in advance.

like image 720
Ryan Avatar asked Aug 22 '14 13:08

Ryan


People also ask

How do you make an ellipsis text in CSS?

This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text. The ellipsis is displayed inside the content area, decreasing the amount of text displayed. If there is not enough space to display the ellipsis, it is clipped. The <string> to be used to represent clipped text.

How do you break a sentence into multiple lines in CSS?

We use the word–break property in CSS that is used to specify how a word should be broken or split when reaching the end of a line. The word–wrap property is used to split/break long words and wrap them into the next line.


1 Answers

You can use text-overflow:ellipsis property with height.

Like this

.truncate 
{
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
height:100px;
}

By using text-overflow, you can display your output without using javascript.

Sources

Source Link

To Learn more about truncating. Read this link

New Update

For multiline ellipsis you can use this method.

css
.classname:after{
content: "\02026";
} 

Multiline-Ellipsis

Few Links which i think might be useful

1.Codepen example

2.Css Tricks

like image 194
Vivek Dragon Avatar answered Nov 15 '22 07:11

Vivek Dragon