3

I want to truncate text according to div size

this is the code snippet:

<div style="padding-left:10px; width:200px; border:1px solid #000000">  
  Lorem Ipsum is simply dummy text of the printing and typesetting industry.   
  Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,  
   when an unknown printer took a galley of type and scrambled it to make a type specimen book.   
  It has survived not only five centuries  
</div>

this is my output:

enter image description here

i want my output to be like:

enter image description here

thank you

Ashish Bahl
  • 1,406
  • 1
  • 12
  • 25
ar em
  • 374
  • 2
  • 4
  • 15

3 Answers3

4

div {
  white-space: nowrap;      /* new */
  overflow: hidden;         /* new */
  text-overflow: ellipsis;  /* new */
  padding-left: 10px;
  width: 200px;
  border: 1px solid #000000;
}
<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
  survived not only five centuries</div>

More details: Applying an ellipsis to multiline text

Community
  • 1
  • 1
Michael Benjamin
  • 265,915
  • 79
  • 461
  • 583
1

Apply following style to your div.

div{
    padding-left: 10px;
    width: 200px;
    text-overflow: ellipsis;
    overflow: hidden;
    border: 1px solid #000000;
    white-space: nowrap;
}
Learner
  • 157
  • 1
  • 2
  • 11
0

You will need to give it a height and use text-overflow: ellipsis;

You can use this class.

.no-overflow {
  padding-left:10px; 
  width:200px; 
  border:1px solid #000000;
  height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
}
sgsvnk
  • 1,991
  • 2
  • 17
  • 45