1

I use this code:

.truncated-filename {
    max-width: 100px;
    text-overflow: ellipsis;
}

To prevent filenames from being too long for the box. However, there seems to be a vertical overflow issue. How can I make it so it just puts the dots on the top line?

enter image description here

3
  • You can use white-space: nowrap; to make the text follow a single line Commented Dec 3, 2015 at 2:23
  • looks something like this .truncated-filename { max-width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } Commented Dec 3, 2015 at 2:30
  • Ellipsis requirements and limitations: stackoverflow.com/a/33061059/3597276 Commented Dec 3, 2015 at 3:15

1 Answer 1

3

It looks like you need to add overflow: hidden and white-space: nowrap.

The text won't be truncated unless it doesn't wrap, which is why you needed white-space: nowrap and an overflow value other than visible.

.truncated-filename {
  border: 1px solid;
  display: inline-block;
  max-width: 100px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
<span class="truncated-filename">10128-teach-vector.png</span>

Sign up to request clarification or add additional context in comments.

1 Comment

...according to MDN, text-overflow: ellipsis only works with overflow: hidden.. You may want to revise that. MDN only suggests it as an example. And text-overflow: ellipsis will work as long as overflow is other than visible... jsfiddle.net/9t2w7yex/2 ... In case you're interested, I have a full answer here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.