Skip to content

Instantly share code, notes, and snippets.

@mazhar266
Last active August 29, 2015 14:04
Show Gist options
  • Save mazhar266/4a27978a21797f4e16d2 to your computer and use it in GitHub Desktop.
Save mazhar266/4a27978a21797f4e16d2 to your computer and use it in GitHub Desktop.
Limiting text with (...) in CSS

We can put … in place of '...'. Because it's one character and it's easy to calculate

function shorten(text, maxLength) {
var ret = text;
if (ret.length > maxLength) {
ret = ret.substr(0,maxLength-3) + "...";
}
return ret;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment