Skip to content

Instantly share code, notes, and snippets.

@dejurin
Forked from elky/truncate.css
Created June 5, 2022 19:29
Show Gist options
  • Save dejurin/f5ca23fdcd5348b6d22385ff57c20900 to your computer and use it in GitHub Desktop.
Save dejurin/f5ca23fdcd5348b6d22385ff57c20900 to your computer and use it in GitHub Desktop.
text-overflow ellipsis with 100% width
/*
Demo: https://jsfiddle.net/elky/f6khaf2t/
<div class="element">
<div class="truncate">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
*/
.element {
display: table;
table-layout: fixed;
width: 100%;
}
.truncate {
display: table-cell;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment