Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using text-overflow ellipsis in middle of list items

Tags:

html

css

I am trying to implement HTML/CSS where there are four list items (li) within a full-width unordered list element (ul), but am struggling to get one of those items to use the text-overflow:ellipsis command.

The result should be something along these lines...

+-------------------------------------------------------------------------------------------+
| Item One | Item Two Two Two Two Two Two Two Two Two Two Two ...  | Item Three | Item Four |
+-------------------------------------------------------------------------------------------+

The 1st, 3rd and 4th items are to be locked in position - with the 1st item on the left, and the 3rd and 4th items "locked" to the right hand side of the full-width area.

The 2nd item should take all the remaining space, with ... ellipsis on the overflow.

This area will be used within a responsive design, and therefore will expand/shrink depending on the available screen area.

All four of the items will contain variable amounts of text, however the 2nd item will always have the most. So the 1st, 3rd and 4th should always be fully visible... but the 2nd should hide what doesn't fit.

This the the closest I've got (using two ul controls, floating the 3rd and 4th items on the right hand side), but as soon as I add the CSS for the 2nd item, it all goes wrong. (By "wrong", I mean the 2nd item wraps onto the next line rather than staying on the same line and showing the ...)

#leftul {
    width:100%;
}
#rightul {
    float:right;
}
ul {
    margin:0;
    padding:0;
}
li {
    list-style-type:none;
    display:inline-block;
    border:1px solid black;
}
#leftul #leftlarge {
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
}
<ul id="rightul">
    <li>Item Three</li>
    <li>Item Four</li>
</ul>
<ul id="leftul">
    <li>Item One</li>
    <li id="leftlarge">Item Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two</li>
</ul>

Can anybody please suggest how this could be possible to acheive?

like image 548
freefaller Avatar asked Aug 31 '15 12:08

freefaller


People also ask

How do you text-overflow on ellipsis?

To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.

Why is text-overflow ellipsis not working?

text-overflow: ellipsis only works when the following is true: Parent element is not set to display: inline (span's default,) You must use display: block or display: inline-block. The element's width must be constrained in px (pixels) – it doesn't work with values specified using % (percent.)

What does text-overflow ellipsis mean?

A text-overflow property in CSS is used to specify that some text has overflown and hidden from view. The white-space property must be set to nowrap and the overflow property must be set to hidden. The overflowing content can be clipped, display an ellipsis ('…'), or display a custom string.


1 Answers

This code is working fine, try this way

<div class="left">left</div>
<div class="right">right</div>
<div class="right">right</div>
<div class="middle"><div  class="flexible_width1">Item Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two</div></div>

Css:

.left{
    background:red;
    min-width:70px;
    float:left;

}
.middle{
    background:yellow;

}
.right{
    float:right;
    min-width:70px;
    background:green
}
.flexible_width1 {
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;

}

Demo

like image 54
Arun Kumar M Avatar answered Nov 05 '22 10:11

Arun Kumar M