1

I'm trying to add [read more] button to multiple line ellipsis layer.

<p class="description">this is long text.this is long text. <button type="button">expand</button></p>

.description {
  width: 300px;
  text-overflow: ellipsis;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.description button {
  margin: 0; padding: 0 0 0 10px;
  background-color: transparent; border-width: 0; outline-width: 0;
  font-size: 14px; color: #3f8f7b;
}

https://jsfiddle.net/redhork7/symuzrmt/

the result should be like,

this is long text.this is long text.this is long text.this is long text.
this is long text.this is long text.this is long text.this is long text.
this is long text.this is long text.this is long text...   [more button]

is it possible?

3 Answers3

0

The button needs to be at the right margin of the last line or it can be below the text block? If yes, put it outside the text element
but
if you need it to be at the bottom right corner, you can set the text content as position:relative and the button as position:absolute /right:0 /bottom:0 , however this way the button is going to overlap the characters at the end of the box.

Marcelo F.
  • 385
  • 1
  • 3
  • 7
0

Try This:

.wrapper {
  position: relative;
  display: inline-block;
  width: 360px;
}

.description {
  width: 300px;
  text-overflow: ellipsis;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.btn {
  margin: 0; padding: 0 0 0 10px;
  background-color: transparent; border-width: 0; outline-width: 0;
  font-size: 14px; color: #3f8f7b;
  position: absolute;
  bottom: 15px;
  right: 0;
  cursor: pointer;
}
<div  class="wrapper">
 <p class="description">this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text.this is long text. </p>
        <button type="button" class="btn">expand</button>
</div> 
Ehsan
  • 12,655
  • 3
  • 25
  • 44
0

I've just found javascript library for adding more button after ellipsis(...).

it supports the option, jQuery.dotdotdot({ 'after': '.classname' }) for add button.