I need to implement ellipsis (\"...\") in the middle of a text within a resizable element. Here is what it might look like. So,
\"Lorem ipsum do
I'd like to propose mine example of solving this problem.
The main idea is to split text in two even parts (or first is bigger, if the length is odd) one of which has ellipsis in the end and another aligned right with text-overflow: clip.
So all you need to do with js, if you want to make it automatic/universal - is to split string and set attributes.
It has some disadvantages, though.
text-overflow: '' works only in FF at the moment)direction: rtl - they will be moved to the left of the string. I think, it is possible to fix this with putting right part of the word in the tag and exclamation mark in the ::after pseudo-element. But I haven't yet made it properly working.But, with all of these, it looks really cool to me, especially when you dragging the border of the browser, which you can do on the jsfiddle page easily: https://jsfiddle.net/extempl/93ymy3oL/. Or just run the snippet with fixed max-width below.
Gif under the spoiler:
body {
max-width: 400px;
}
span::before, span::after {
display: inline-block;
max-width: 50%;
overflow: hidden;
white-space: pre;
}
span::before {
content: attr(data-content-start);
text-overflow: ellipsis;
}
span::after {
content: attr(data-content-end);
text-overflow: '';
direction: rtl;
}