Is there a way to apply text-overflow: ellipsis
to a flexbox element?
I know I need to set the width
and overflow: hidden
, but how can I achieve the ellipsis effect within the grey block when the text overflows?
Removing the flexbox property from the <a>
tag allows the ellipsis to work, but I need to maintain the layout by adding an icon at the top using flex-direction: column. If I remove the display: flex, the layout breaks.
Any advice on how to overcome this issue?
div {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid red;
width: 200px;
height: 200px;
}
span {
display: flex;
boder: 1px solid blue;
}
a {
background: lightgrey;
display: flex;
/* Once I set the <a> as a flex, the-overflow: ellipsis doesn't work */
align-items: center;
justify-content: center;
flex-direction: column;
flex: 0 1 100px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 100px;
}
a:before {
content: 'icon';
background: lightblue;
height: 45px;
width: 45px;
margin-bottom: 8px;
}
<div>
<span>
<a>test123tfdsfsdafdsaffdsfdsafsadfest456</a>
</span>
</div>