I've got a div
, which is a wrapper, and some child div
within. I'm using flexbox
to position them below each other. Now, the child divs have a text. The text is aligned vertical with align-items: center;
. The width of the child div depends of it's text. When the text is as long as the wrapper, the div should stop growing and the text within should got cut of. For this I tried to use text-overflow: ellipsis;
. It doesn't work as expected. I know I could use display: inline-block;
in case of flexbox
, but I would like to use flexbox
to align the text in combination with text-overflow: ellipsis;
but it seems not to work with my example. At the moment, the item with long text overlaps the wrapper and there is also no ellipsis. The item has an fix height.
The only answer I found for this topic was this one, but the answer didn't help me: Ellipsis in flexbox container
Hope it's clear enough.
.wrapper {
display: flex;
flex-direction: column;
background-color: lightcoral;
padding: 10px;
flex-wrap: wrap;
}
.wrapper__item {
min-width: 0;
flex-basis: 50%;
align-self: flex-start;
flex-direction: row;
width: auto;
max-width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
padding: 5px 10px;
border: 1px solid black;
border-radius: 5px;
margin-bottom: 10px;
background-color: white;
height: 50px;
}
<div class="wrapper">
<div class="wrapper__item">Proin eget tortor risus. Cras ultricies ligula sed magna dictum porta. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec rutrum congue leo eget malesuada. Vivamus suscipit
tortor eget felis porttitor volutpat. Nulla porttitor accumsan tincidunt. Curabitur aliquet quam id dui posuere blandit. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Donec rutrum congue leo eget malesuada. Curabitur arcu
erat, accumsan id imperdiet et, porttitor at sem. Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a. Nulla porttitor accumsan tincidunt. Cras ultricies ligula sed magna dictum porta.</div>
<div class="wrapper__item">Proin eget tortor ri.</div>
<div class="wrapper__item">Proin eget tortor ri.Proin eget tortor ri.</div>
</div>
flex-wrap: wrap;
on the wrapper and amin-width
of 0 and aflex-basis
of 50% on the item. The rest is similar to mine. Maybe I did it wrong I don't know... – Paediatrician