CSS ellipsis not working for this div - css

A representative code sample:
<div style="width:300px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
<ul>
<li>Long name: <span>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</span></li>
</ul>
</div>
http://jsfiddle.net/G57LE/
It seems only the overflow property will do anything here.
How do I get the text to do an ellipsis on overflow for this div (where the ellipsis happens just before the end of the div)? Thanks!

Because the text isn't in the div itself. You would have to apply the width and overflow attributes to the span itself.
Possible solution for you: CSS text ellipsis when using variable width divs

add this
display: inline-block; overflow: hidden; text-overflow: ellipsis; width:300px;
to span's class .value
here is http://jsfiddle.net/G57LE/5/

Related

how to truncate last element if needed

I have a div with different number of span inside depending on my code, my problem is, sometimes the last span does not fit the space and everything lost the align, what I want to do is applied my "truncate" class to the last element if needed, there is an example:
<div class="truncate">
<span> ONE </span>
<span> TWO </span>
<span> THREE </span>
<span> FOUR </span>
</div>
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
with this configuration, and also aplying "truncate" everything moved to left, and I stop watching "one" instead "four" as I want, either the "..." are not shown.
I also tried aplied truncate to the last child with same result:
.truncate:last-child {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Where is my mistake?
Check out the :last-child pseudo-class.
Might not be relevant to you now, but I had this problem, and I solved it with flex-shrink: 0 which tells certain elements never to shrink, which means that last element shrinks.
See example: https://jsfiddle.net/68usz20p/2/
div {
display: flex;
overflow: hidden;
width: 175px;
border: 1px solid red;
}
div span:not(:last-child) {
margin-right: 1ch;
flex-shrink: 0;
}
div span:last-child {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
You can using css :last-child Selector
.truncate span:last-child {
display:none; visibility:hidden;
}
<div class="truncate">
<span> ONE </span>
<span> TWO </span>
<span> THREE </span>
<span> FOUR </span>
</div>
Preview at https://jsfiddle.net/itsselvam/yt9srxLo/

How to shrink a child to fit the outer-most flex-container in a deep hierarchy? [duplicate]

This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
CSS ellipsis inside flex item
(1 answer)
Closed 4 years ago.
I am trying to hide overflow in a label that is the child of a deeply nested flex-container. Below are two simple snippets to illustrate the problem:
Single container (works):
#parent-flexbox {
display: flex;
width: 200px;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div id="parent-flexbox">
<label>long text that should be hidden because it is wider than the parent container</label>
</div>
Nested container (doesn't work):
#parent-flexbox {
width: 200px;
}
#parent-flexbox, #child-flexbox {
display: flex;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div id="parent-flexbox">
<div id="child-flexbox">
<label>long text that should be hidden because it is wider than the parent container</label>
</div>
</div>
To solve this I could add an explicit width like max-width: 100% to every container in the hierarchy. This is a terrible solution that I'm hoping is unnecessary! My current best fitting solution, but not much better, is these two rules for the immediate parent of the label: {position: absolute; max-width: 100%}. I want to avoid using absolute position because this comes with problems of its own. This JSFiddle shows the absolute position solution (lines outcommented default).
How can I achieve the same as this JSFiddle without A) using position: absolute and B) targetting all containers in the hierachy to give them max-width: 100% or min-width: 0?
The issue here is that the nested container is overflowing the first container and that's why overflow hidden is not working as you expect since there is no overflow with label.
I added border so you can better see:
#parent-flexbox {
width: 200px;
}
#parent-flexbox, #child-flexbox {
display: flex;
border:1px solid green;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div id="parent-flexbox">
<div id="child-flexbox">
<label>long text that should be hidden because it is wider than the parent container</label>
</div>
</div>
To avoid this you may apply overflow:hidden to the containers:
#parent-flexbox {
width: 200px;
}
#parent-flexbox, #child-flexbox {
display: flex;
overflow: hidden;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div id="parent-flexbox">
<div id="child-flexbox">
<label>long text that should be hidden because it is wider than the parent container</label>
</div>
</div>
I don't think you can fix this without targeting the containers. And since your are applying display:flex to all of them, you can add another property with it.

text-overflow: ellipsis; not working with mat-expansion-panel

I'd like to apply text-overflow: ellipsis; to the mat-panel-description of a mat-expansion-panel:
.mat-expansion-panel-header-description {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 100%;
}
While the overflow is hidden, there are no ellipsis. See the following screenshot of this stackblitz:
Wrapping is intentionally prevented since I don't want the description to wrap onto a second line. The long URL is also intentional:
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
Panel Title
</mat-panel-title>
<mat-panel-description>
https://stackblitz.com/edit/angular-gsxyhn?file=app%2Fexpans ion-overview-example.html
</mat-panel-description>
</mat-expansion-panel-header>
</mat-expansion-panel>
</mat-accordion>
I think you will come to find out that if you just put text in flex containers you can run into problems. I think it is best if you have a container element to hold your text and will help you in this case.
Once the content is placed in some container, there is one thing that needs to be done to get the ellipsis to show up... add min-width: 0; to the mat-expansion-panel-header-description class.
<span class="mat-content">
<mat-panel-title class="mat-expansion-panel-header-title">
<div>Panel Title</div>
</mat-panel-title>
<mat-panel-description class="mat-expansion-panel-header-description">
<div>https://stackblitz.com/edit/angular-gsxyhn?file=app%2Fexpans ion-overview-example.html</div>
</mat-panel-description>
</span>
.mat-expansion-panel-header-title {
flex: 0 0 auto; /* make this not grow or shrink */
margin-right: 16px;
}
.mat-expansion-panel-header-description {
flex: 1 1 auto; /* make this grow and shrink */
min-width: 0; /* see link to see why this is needed */
margin-right: 16px;
}
.mat-expansion-panel-header-description > div {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
I solved it changing the child's visibility property.
Take a look here.
Ellipsis won't work on a visibility: hidden element, or any of its children inheriting this property.

Multiline ellipsis with <br> tags only adds ellipsis to first line in IE11/Edge

In Chrome and Firefox both lines show an ellipsis at the end. However in IE11/Edge only the first line has an ellipsis and the second line is simply cutoff. Is there anyway to get IE11/Edge to work similar to Chrome/Firefox?
body {
font-family: 'Arial';
}
div.wrapped-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100px;
}
<div class="wrapped-text">
This is a test of wrapped<br>
text that should overflow
</div>
For anyone in the same situation I've found the only way to get this to work is to change the HTML a little so that each line in the div is wrapped in its own div - and those child divs get the css to add the ellipsis.
body {
font-family: 'Arial';
}
div.wrapped-text {
width: 100px;
}
div.wrapped-text > div {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<div class="wrapped-text">
<div>This is a test of wrapped</div>
<div>text that should overflow</div>
</div>

CSS - word-wrap with input and label DOM elements

Link to jsfiddle: http://jsfiddle.net/WBZng/1/
I have a HTML structure that looks like this:
<div>
<input/>
<span>Label comes here...</span>
</div>
Both input and span should have display:inline. Also, span has word-wrap:break-word so that a long text without space still becomes wrapped. However, if the text is long, then the <span> is displayed in a new line instead of preserving display:inline-block. This is not an issue if there is a space in <span>.
You can consider giving ellipsis to the span element:
.panel span {
width: 20px;
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
​
Fiddle: http://jsfiddle.net/WBZng/3/

Resources