Beyond the text-overflow: ellipsis
, you must still use the property white-space
, that defines how the white space inside an element is manipulated. Also the property overflow
as Hidden, which specifies when the contents of a block level element should be cut. Here’s what your code should look like:
.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>
It is also possible to do multilines using the webkit
. See below 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>
I was behind this a long time ago and found this example, if you want to take a look http://codepen.io/chriscoyier/pen/iBtep
– Vitor Adriano
Thanks, very good this example and functional, but p/ my case I can only make change in css I believe that the @Ack Lay example will suit me better but your solution can help other users, congratulations
– Juliano da Silva Barbosa