I am trying to truncate the long text in the span
with id first-item
, when the screen gets smaller. However, when margins are set on the parent, it cannot shrink and therefore truncate does not seem to work. I believe it is related to Why don't flex items shrink past content size? but I could not make it work.
body {
display: flex;
flex-direction: column;
}
main {
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
}
#container {
display: flex;
}
#first-item {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<body>
<main>
<div id="container">
<span id="first-item">Long long long long long long long long long long long long long long long long long long long long long long long long long text to be truncated</span>
<span>Shorter text</span>
</div>
</main>
</body>
EDIT: As @AmauryHanser commented, there was a typo in the initial version of the post, which is now corrected. Even though it seems that the ellipsis is there, it can only shrink to a point and the problem is still there. Check the screenshot below.