When you give align-items: center
the text
overflows the parent
and the width is not constrained and so ellipsis will not appear.
If you remove align-items: center
it works because align-items: stretch
is the default - but the image get stretched out now:
.parent {
border: 1px solid red;
display: flex;
/*align-items: center;*/
flex-direction: column;
width: 300px;
}
.text {
white-space: nowrap;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="parent">
<img src="http://placekitten.com/g/200/200" />
<div class="text">
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
</div>
</div>
Solution
Add width: 100%
to the text
- see demo below:
.parent {
border: 1px solid red;
display: flex;
align-items: center;
flex-direction: column;
width: 300px;
}
.text {
white-space: nowrap;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}
<div class="parent">
<img src="http://placekitten.com/g/200/200" />
<div class="text">
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
</div>
</div>
The min-width: 0; hack doesn't work when flex-direction is set to
column.
Note that in min-width: 0
if for overriding the the flex item width as it is auto in the row direction (for column direction you use min-height
). See example below for min-height: 0
used in a column flexbox: