Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using text-overflow:ellipsis; only when reaching 3 lines in a div [duplicate]

this is my css snippet

.test{
    width:150px;
    height:60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}

what it does is..

the quick brown fo...

what i want is

the quick brown fox
jumps over the lazy
dog. the quick br...

is there anyway to do this with just CSS? or do i need to use javascript for this. If javascript is needed, anyone can teach me how? thanks!

UPDATE

i tried removing the white-space: nowrap; and added overflow-y: hidden; it gives me the 3 line layout but no ellipsis

.test{
    width:150px;
    height:60px;
    overflow-y: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
}
like image 716
galao Avatar asked Apr 26 '13 06:04

galao


People also ask

How do you overflow an ellipsis text?

To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.

How do I truncate text after two lines?

2) Truncate text after multiple lines using line-clamp With line-clamp text can be truncated after multiple lines, whats even more interesting is you can truncate it by specifying the line number where you want to truncate it. eg: -webkit-line-clamp: 3; will truncate start truncating the text from the third line.

How do I limit a text line in CSS?

The easiest way to limit text to n lines is to use line-clamp . N can be any positive number, but it will be two or three lines most of the time. On my blog, I'm using line-clamp in all post-type components to ensure that it will have the same height as siblings.


2 Answers

you could use the dotdotdot plugin http://dotdotdot.frebsite.nl/, it works fine for me.

pure css can work in some broswers, but it has many limits. Suppose you want ... at the end of the line3.

.test{
   display: -webkit-box;
   height: 60px; 
   -webkit-line-clamp: 3;
   -webkit-box-orient: vertical;
   text-overflow: ellipsis;
 }
like image 152
Robin Hwang Avatar answered Oct 14 '22 17:10

Robin Hwang


You can also try this one

.test { width: 150px; height: 60px; overflow-y: hidden; position: relative; }

.test:after { content: '...'; position: absolute; bottom: 0; right: 0; }
like image 4
Manish Sharma Avatar answered Oct 14 '22 17:10

Manish Sharma