Well, I believe that this is what you wanted to achieve. Below is the code with descriptions in the comment blocks. In chrome you will use the -webkit-line-clamp property, in firefox you will use the fadeout method, since firefox does not support the clamp property. You can customize fadeout in css to your liking. The "..." at the cutoff point will also be present in firefox (see .clamp:after property in css).
Here is the updated jsFiddle
HTML (To see the changes, just delete the text until one line is shown in the div)
<div id="textparent"> <div id="text"> {{content}} adkf kfjg; ;akdfg fbfbf egdf hajkh kajfhdg lakjfg kafd gjkahf jahfkjadlfh alkgj akjdhg fkafg </div> </div>
CSS
Note: -webkit-line-clamp: 3; (this is the number of lines you want to display)
#text{ width:100%; position:relative; height:auto; text-overflow:ellipsis; font-size:25px; line-height:1.1; display:block; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp:3; overflow:hidden; margin:0 auto; box-sizing:border-box; } #textparent{ margin:0 auto; width:300px; background:#eee; top:50px; padding:10px; height:auto; text-align:center; position:relative; height:100px; display:-webkit-box; -webkit-box-pack:center; -webkit-box-align:center; } .clamp:after { background: linear-gradient(to right, rgba(255, 255, 255, 0), #eeeeee 50%) repeat scroll 0 0 rgba(0, 0, 0, 0); bottom: 0; content: "..."; padding: 0 5px 1px 25px; position: absolute; right: 0; } .clamp { height: 5.6em; line-height: 1.4em; overflow: hidden; position: relative; }
Javascript / JQUERY: The main variable you can change or play is [min_font_size] and [num_line_to_show], although [num_line_to_show] is already set in CSS.
var t = $('#text'); // get the font-size of the div var font_size = Number(t.css('font-size').replace('px', '')); // get the line-height of the div (Note: in Chrome this returns the actual height) var line_height = Number(t.css('line-height').replace('px', '')); // minimum height of
Note. You can also try setting the minimum font size dynamically, something like this:
Continuation:
// for detecting firefox var is_ff = navigator.userAgent.toLowerCase().indexOf('firefox'); // if the height of the div is larger than the minimum height, meaning there // is more than one line now, the font size of the div becomes smaller. if (h > min_h){ t.css({'font-size' : min_font_size}); // if in Firefox browser if(is_ff > -1){ // get the new max height of
Hope this helps!