Add … if string is too long


/ Published in: CSS
Save to your folder(s)

Add ... using css when string or title not fit on place
Add … if string is too long

Now, assuming the element has a fixed width, the browser will automatically break off and add the ... for you.


Copy this code and paste it in your HTML
  1. $out = strlen($in) > 50 ? substr($in,0,50)."..." : $in;
  2.  
  3. or
  4.  
  5. .ellipsis {
  6. overflow: hidden;
  7. white-space: nowrap;
  8. text-overflow: ellipsis;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.