A framework I am using that generates HTML code outputs the following:
body {
width: 200px; /* ignore this, this is only for demonstration purpose */
}
<div class="select-option-text" style="white-space: nowrap; overflow: hidden;">
Some very long text that should be truncated with an ellipsis if it's too long to fit
<span class="select-option-secondary-text">Always show</span>
</div>
What I want to achieve is to always have .select-option-secondary-text
visible next to the text. With a short text, this works fine, but if the text is long like in my example, it pushes the .select-option-secondary-text
off the visible area.
I wasn't able to fix this using flexbox, but I was able to get somewhat near my requirement using grid:
body {
width: 200px; /* ignore this, this is only for demonstration purpose */
}
.select-option-text {
display: grid;
grid-auto-flow: column;
grid-template-columns: minmax(0, 1fr) auto;
}
<div class="select-option-text" style="white-space: nowrap; overflow: hidden;">
Some very long text that should be truncated with an ellipsis if it's too long to fit
<span class="select-option-secondary-text">Always show</span>
</div>
However, the first "cell" still overflows into the second "cell". Using a background color is not really an option because .select-option-text
has its own background color set programmatically with JS and I don't know that color.
I also cannot wrap the long text into a span
or something because as I said, this structure is created dynamically by a third-party JS library.
Anything I can do to prevent the text from spilling into the next cell, maybe even truncate it with an ellipsis?