2

Well, I have content within a paragraph, maybe like this:

<div style="width:30px">
  <p>12345678901234567890abcdefghijklmnopqrstuvwxyzIlovePaulinaVega</p>
</div>

We all know that the content will be divided into many rows because of its parent's width, but I just want to keep the top 2 rows, the rest is replaced with'...'. I am wondering how to accomplish it .Tell me please.

2 Answers2

1

p {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
<div style="width:100px">
  <p>12345678901234567890abcdefghijklmnopqrstuvwxyzIlovePaulinaVega</p>
</div>

Add CSS like this:

p{
  text-overflow:ellipsis; 
  white-space:nowrap;
  overflow:hidden;
 }
Sandeep Nayak
  • 4,649
  • 1
  • 22
  • 33
1

Try this

JsFiddle:

http://jsfiddle.net/2zggrdur/1/

CSS:

p {
        line-height: 1.5em;
        height: 3em;
           text-overflow:ellipsis; 
        overflow: hidden;
    }
  1. Specify height property to visible number lines or rows in your paragraph.
  2. text-overflow:ellipsis and overflow:hidden will do hide and 3 dots properties.
  3. Allighn parent width according to paragraph.
Andi AR
  • 2,678
  • 2
  • 23
  • 28
  • well, I replaced content within

    with 'sssssssssssssssssssssssssssssss...'(however, a lot of ss), It doesn't work... but thank you all the same. I think this problem should be solved with jquery
    – Patrickgao91 Oct 12 '15 at 09:09