Solution 1:
Use the webkit property only -webkit-line-clamp for two lines.
.overme { width: 300px; height: 60px; line-height: 30px; overflow:hidden; font-size: 30px; color: red; background: #333; white-space:nowrap; text-overflow: ellipsis; } .overme { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
<div class="overme"> how much wood can a woodchuck chuck if a woodchuck could chuck wood? </div>
Decision 2
Use the :after pseudo-element aligned in the lower right corner. This only works if your text is static and you know in advance that the container will overflow.
.overme { width: 300px; height: 60px; line-height: 30px; overflow:hidden; font-size: 30px; color: red; background: #333; position: relative; } .overme:after { display: inline-block; position: absolute; right: 0; bottom: 0; content: '...'; }
<div class="overme"> how much wood can a woodchuck chuck if a woodchuck could chuck wood? </div>
Solution 3 - Cross Browser
This JS solution compares the height of the parent container (div) with the content text. If the height of the text is greater than the parent height, the .overflows class is added to the parent element.
To check this, delete some text so that it matches all parents. You will no longer see the point.
$(".overme").each(function () { var $elem = $(this); $elem.addClass($elem[0].scrollHeight > $elem.height() ? 'overflows' : null); });
.overme { width: 300px; height: 60px; line-height: 30px; overflow:hidden; font-size: 30px; color: red; background: #333; position: relative; } .overme.overflows:after { display: inline-block; background: #333; position: absolute; right: 2px; bottom: 0; content: '...'; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="overme"> how much wood can a woodchuck chuck if a woodchuck could chuck wood? </div>
source share