In addition to text-overflow: ellipsis
, you should still use the white-space
, which defines how white space within an element is handled. Also the property overflow
as hidden , which specifies when the contents of a block level element should be cut. Here's how your code should look:
.box {
max-width: 250px;
font-size: 20dp;
white-space: nowrap;
overflow: hidden; /* "overflow" value must be different from "visible" */
text-overflow: ellipsis;
border: 1px solid #ccc;
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas fermentum nisi ut auctor posuere. Fusce pulvinar blandit commodo.
Nulla nunc nunc, ultrices vitae aliquam sit amet, aliquam a metus. Aenean
semper nisi sed augue elementum tincidunt. Maecenas sit amet magna id lectus
tempor luctus in quis justo. Proin vel iaculis.
</div>
You can also do multilines using webkit
. Here is an example with 3 lines:
.box {
display: block;
display: -webkit-box;
max-width: 250px;
font-size: 20dp;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #ccc;
}
<div class="box">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Maecenas fermentum nisi ut auctor posuere. Fusce pulvinar blandit commodo.
Nulla nunc nunc, ultrices vitae aliquam sit amet, aliquam a metus. Aenean
semper nisi sed augue elementum tincidunt. Maecenas sit amet magna id lectus
tempor luctus in quis justo. Proin vel iaculis.
</div>