Problem
I have navigation tabs which are horizontaly scrollable and my task now is to add function that if you scroll this "menu" left or right and the title in nav tab overflows it should add "…" dots to that title. Basically when you scroll to right and you stop scrolling in the middle of the word it should replace this remaining part with dots (same thing when you scroll left )
At first this menu was implemented without these dots and arrows but customers were arguing that they did not know that there were another tabs they could click (on mobile phones)
Figma preview
preview of figma implementation with visible right and left arrow with text overflow dots
So far all my attempts failed and I’m trying to understand it from scratch but from what I see I do not know if it’s even possible ?
<div class="with-elipsis">Test paragraph with <code>ellipsis</code>. It needs quite a lot of text in order to properly test <code>text-overflow</code>.</div>
<div class="with-elipsis-scroll">Test paragraph with <code>string</code>. It needs quite a lot of text in order to properly test <code>text-overflow</code>.</div>
.with-elipsis {
width: 500px;
text-overflow: ellipsis;
border: 1px solid #000000;
white-space: nowrap;
overflow: auto;
}
.with-elipsis-scroll {
border: 1px solid #000000;
white-space: nowrap;
overflow: auto;
height: 40px;
display: flex;
overflow-x: scroll;
width: 200px;
text-overflow: ellipsis;
}
In this code sample:
- context is rendered right but when I scroll the content it scrolls with "dots"
- does not work
2
Answers
I would not try to use
text-overflow
for this. For one thing, it’s not designed to work on both the left and right sides.Instead, I would solve this as per the suggestion from Dale Landry. Personally I would leave out the ellipsis and simply have an arrow or an angle bracket to indicate that scrolling is possible.
Basically the example uses an approach I outlined in the comment section. See notes in code snippet. This could also be achieved using pseudo ::before and ::after as well. Hope this helps in finding an answer to your issue.