Created
September 1, 2016 11:55
-
-
Save elky/ce230d6fcab055104cdf1a3358037fc7 to your computer and use it in GitHub Desktop.
text-overflow ellipsis with 100% width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} |
Waow, nice trick, it works like a charm, many thx!
@elky
I just saw that it doesn't work if the parent element is a button
<button class="element">
<span 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.
</span>
</button>
.element {
display: table;
table-layout: fixed;
width: 100%;
}
.truncate {
display: table-cell;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
@insinfo thanks for noticing. For button
you don't even need that table-hack. Just use the following:
.element {
width: 100%;
}
.truncate {
display: block; /* in case you use span */
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
7 years ago You Sir created this Peace of Art, this Shard of Cosmic Wisdom worthy of Lovecraftian Outer Gods themselves.
And today it saved my life.
I salute You!
I can't thank you enough for this o7
I will be your disciple and spread the good word of how to actually get ellipsis overflow working as reasonable person expects it to work.
Bless your whole family!
God bless you , sir !
With a grateful heart, I thank you, Divine One, for your blessings.
thank you very much!!!!
God bless you 🙏
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
saved my days