Christoph's answer is probably best in the general case, but in my case I knew the text content but not the width of the container, which allowed me to add an extra layer of cheating:
Modify the HTML a bit:
<div id="first" class="container"> <div><span>first_text_section</span></div> </div> <div id="second" class="container"> <div><span>second_text_section</span></div> </div> <div id="third" class="container"> <div><span>third_text_section</span></div> </div>
And using the following CSS:
.container > div { color: transparent; /* don't show the text-overflow content */ overflow: hidden; height: 1em; width: 100%; } /* use the actual text to get the measurement right for hiding */ #first > div { text-overflow: "first_text_section"; } #second > div { text-overflow: "second_text_section"; } #third > div { text-overflow: "third_text_section"; } .container > div > span { color: black; /* do show the span when possible */ }
Then, when changing the width of the container, the full text is either hidden or shown accordingly. If the text contains more than one word, the text is hidden word by word, so you need to know something.
rampion
source share