I have a nav menu in an unordered list:
<ul> <li class="current"> <a href="./">Home</a> </li> <li class=""> <a href="./location/">Location</a> </li> <li class=""> <a href="./rooms-and-rates/">Rooms & Rates </a> </li> <li class=""> <a href="./facilities/">Facilities</a> </li> <li class=""> <a href="./things-to-do/">Things to do</a> </li> <li class=""> <a href="./eating-and-drinking/">Eating and Drinking</a> </li> </ul>
When the menu title is too long, I need to use text-overflow: ellipsis so I am styling my menu links like so in my CSS:
header nav ul li a { text-decoration: none; text-overflow: ellipsis; display: block; overflow: hidden; width: 150px; height: 32px; }
However, the desired effect is not happening. It is just cutting off the whole last word (and wrapping it where it is not visible). Is there anything wrong with my code or is there some caveat that I'm unaware of with text-overflow: ellipsis?
To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.
It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.
The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.
CSS text-overflow: ellipsis; not working? text-overflow:ellipsis; only works when the following are true: The element’s width must be constrained in px (pixels). Width in % (percentage) won’t work. The element must have overflow:hidden and white-space:nowrap set.
Text overflow ellipsis is an important part of UX. Among many usecases, it is often implemented to hide long usernames that don't fit contact list containers. Another usecase is to hide long descriptions in <LI> tags, to avoid breaking single line text flow which would make your ordered (<ol>) or unordered (<ul>) list look less readable and ugly.
So if you reach this question because you're having trouble trying to get the ellipsis working inside a display: flex container, try adding min-width: 0 to the outmost container that's overflowing its parent even though you already set a overflow: hidden to it and see how that works for you.
In chrome, you can apply this css if you need to apply ellipsis on multiple lines. You can also add width in your css to specify element of certain width: <p class="multi-line-ellipsis">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
You need to add white-space: nowrap;
for text-overflow: ellipsis;
to work.
Demo: http://jsfiddle.net/ThinkingStiff/Dc7UA/
a { text-decoration: none; text-overflow: ellipsis; display: block; overflow: hidden; white-space: nowrap; width: 80px; height: 32px; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With