Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text-overflow: ellipsis doesn't appear to be working

Tags:

css

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 &amp; 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?

like image 327
Fraser Avatar asked Jul 08 '12 23:07

Fraser


People also ask

How do I force 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.

Why does overflow hidden not work?

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.

How does text-overflow ellipsis work?

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.

Why is CSS text-overflow ellipsis not working?

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.

What is the use of ellipsis in text overflow?

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.

Why is my ellipsis not working inside a display flex container?

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.

How to apply ellipsis on multiple lines of text?

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.


1 Answers

You need to add white-space: nowrap; for text-overflow: ellipsis; to work.

Demo: http://jsfiddle.net/ThinkingStiff/Dc7UA/

Output:

enter image description here

CSS:

a {      text-decoration: none;      text-overflow: ellipsis;      display: block;      overflow: hidden;      white-space: nowrap;     width: 80px;      height: 32px; } 
like image 189
ThinkingStiff Avatar answered Sep 27 '22 22:09

ThinkingStiff