I need to display text from array I did it with ng-repeat and when the text bigger then 4 lines add ellipsis and link view more I did the ellipsis and also function that return if there are ellipsis and then I display link but its going down a row. I wanna find way to do it... the situation now I would love for you to help me. Attached is html,js code
<div class="comment1 aop-ellipssis four">
{{item.description}}
</div>
<span ng-if="c.isOverflown('comment1',$index)" ng-click="c.openLink(item.sys_id)" class="ag-link" >View More</span>
` function _isOverflown(elem,index){
var element = angular.element('.'+elem)[index];
return element.scrollHeight > element.clientHeight ;}
`
here is a possible average trick , keep some space for that link and set it in absolute position inside a relative parent where stands the text to clamp :
demo below , that fails to hide the motre link if text is filling partially the last line without ellipsis.
edit : to match your screenshot you added, javascript is there for such a job, CSS won't help I'll leave the answer here for curiosity only. :)
div {
width: 400px;
margin: 1em auto 0;
line-height: 1.4;
border-top: solid;
padding-bottom: 1.4em;/* == line-height */
position: relative; /* for coordonate reference to position the more link */
overflow:hidden;/* hide a if here and too far from top */
}
div p { /* text-clipping*/
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
margin: 0;
}
div p+a {
position: absolute;
top: 4.2em;/* == line-height x line-clamp */
right:1rem;
background:#bee
}
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus
lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor,
facilisis luctus, metus</p><a href="#">more</a>
</div>
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p><a href="#">more</a>
</div>
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet.</p><a href="#">more that should not be seen </a>
</div>
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. </p><a href="#">more</a>
</div>