I want to wrap a text within only two lines inside div of specific width. If text goes beyond the length of two lines then I want to show ellipses. Is there a way to do that using CSS?
e.g.
Sample text showing wrapping
of text in only two line...
I want to wrap a text within only two lines inside div of specific width. If text goes beyond the length of two lines then I want to show ellipses. Is there a way to do that using CSS?
e.g.
Sample text showing wrapping
of text in only two line...
CSS only
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
@Asiddeen bn Muhammad's solution worked for me with a little modification to the css
.text {
line-height: 1.5;
height: 6em;
white-space: normal;
overflow: hidden;
text-overflow: ellipsis;
display: block;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
Below worked for me:
CSS:
.longWordBreakParent {
display: flex;
}
.longWordBreak {
word-break: break-all;
}
HTML:
<div className="longWordBreakParent">
<span className='longWordBreak'>someverylongtextthatcannotbefitinoneline</span>
</div>
In all these examples, let’s assume we have:
#someDiv {
width: 250px;
overflow: hidden;
}