I'm want to collapse a long text to a single line and show a MORE
link on the right. The expanded text should show a LESS
link on the bottom and also on the right. Some examples could make it clear:
text text text MORE
text text text text
text LESS
The collapsed state seems to work fine with position: relative; float: right
, but I don't know how to achieve the expanded state. There's nothing like float: right-bottom
(actually even simulating float: bottom
needs a complicated hack, but this hack doesn't seem to be usable in my case). The algorithm is trivial: If there's enough space after the text, put it at the end of the last line, otherwise, put it in a next line (also right-aligned), but how to tell the browser?
More examples, how it should work.
text MORE
text a_long_word
text text text LESS
text a_long_word
an_even_longer_word
LESS
Note that the line text MORE
should be produced as a shortened version of the lines below.
I sort of got it working with something like
<div><a>MORE</a><span>the text....</span><a>LESS</a></div>
hiding one of the links, and setting overflow: hidden; height: 20px;
in the collapsed case. Now, I'd like to get text-overflow: ellipsis
, too...
I'm not looking for a pure CSS solution. I know the height of the expanded text and if I also knew where it ends horizontally, I'd position MORE
absolutely and call it a day.