1

Details :

I have problem in css text-overflow. Actually my div contains large text content but I want it to display only four lines and I want to remove this overlapping content. How could I achieve this?

My overlapping content

overlapping div

CSS Code :

.divclass {
    width:90%;
    display: block;
    float: right; 
    text-overflow: ellipsis;
    overflow:hidden;
}
kamesh
  • 2,374
  • 3
  • 25
  • 33

6 Answers6

2

You can't use pure css text-overflow with multi-line text (sorry)

You'd be best using something like dotdotdot:

$(document).ready(function() {
    $(".divclass").dotdotdot();
});
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
1

As a curiosity, it can be done with webkit browsers:

display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
Samuli Hakoniemi
  • 18,740
  • 1
  • 61
  • 74
0

You can use sub string in javascript or try this:

Sample:

var strings = 'Text contents';
if(strings.length > 10) 
strings = strings.substring(0,10);
0

Give your .divclass a specified height

 .divclass { max-height: 150px; }

or whatever max-height your four lines require

Abhi
  • 350
  • 1
  • 4
  • 13
  • @Ahni i agree with you but i have one question . if suppose i increase my font-size again same problem will come right? – kamesh Mar 11 '14 at 10:56
  • Yes, increasing the font-size will eventually make the text behave the same way it is behaving now, if it exceeds the height boundries. Better keep a particular font-size for this div. – Abhi Mar 11 '14 at 11:10
0

try this white-space:nowrap;

.divclass {
width:90%;
display: block;
float: right; 
text-overflow: ellipsis;
overflow:hidden;
white-space:nowrap; 
}
Anand Natarajan
  • 1,172
  • 8
  • 7
  • In your code only one line is displaying but i want to display first four lines and at the end of the fourth line '...' – kamesh Mar 11 '14 at 11:00
-1

Use this, It's work without jQuery

.divclass {
            height:25px;
            overflow:hidden;
            width:50%;
            text-overflow:ellipsis;
            display:block;
            white-space:nowrap;
        }
Jagdish
  • 1
  • 1