Skip to content

Instantly share code, notes, and snippets.

@FFKL
Last active September 2, 2025 15:54
Show Gist options
  • Save FFKL/9018d68ac764d01817221145a6d09a21 to your computer and use it in GitHub Desktop.
Save FFKL/9018d68ac764d01817221145a6d09a21 to your computer and use it in GitHub Desktop.
Auto-resizable ellipsis without fixed width ๐Ÿ˜ฎ
.ellipsis {
position: relative;
}
.ellipsis:before {
content: ' ';
visibility: hidden;
}
.ellipsis span {
position: absolute;
left: 0;
right: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<td>
<div class="ellipsis">
<span>Very very long text for this cell</span>
</div>
</td>
@George-Al3xander
Copy link

Thanks, great workaround, works as expected!

@bryanbraun
Copy link

Yes very helpful. I made an interactive version here so I could fiddle with it.

As a note to anyone else, the .ellipsis:before pseudo-element is needed because it prevents the box containing the overflowing text from collapsing vertically. The issue becomes noticeable when you have other text or content after the text with the ellipsis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment