The accepted answer is awesome. However, you can still use %
width and attain text-overflow: ellipsis
. The solution is simple:
display: inline-block; /* for em, a, span, etc (inline by default) */
text-overflow: ellipsis;
width: calc (80%); /* The trick is here! */
It seems whenever you use calc
, the final value is rendered in absolute pixels, which consequentially converts 80%
to something like 800px
for a 1000px
-width container. Therefore, instead of using width: [YOUR PERCENT]%
, use width: calc([YOUR PERCENT]%)
.