I'm aware of these posts:
- Prevent a child element from overflowing its parent in flexbox
- text-overflow ellipsis on flex child not working
- Why don't flex items shrink past content size?
No answer from there fixes the issue I have in the code snippet below. Here's the html tree:
- parent flex column
- child flex row
- label flex (so I can align text vertically)
- child flex row
The only way I could make it work is by making the label an inline-block
, but I'd really like to keep the flex.
What I'd already done:
- On the child:
- Set
white-space: nowrap
- Set
min-width: 0
- Set
overflow: hidden
- Set
- On the parent
- Set
min-width: 0
- Set
- Permutate the options above with
flex-grow: 1
andmax-width: 100%
.parent-container {
align-items: stretch;
display: flex;
flex-flow: column nowrap;
width: 100%;
}
.item-container {
border: 1px solid #ebf0ff;
border-radius: 0.25rem;
display: flex;
flex-flow: row nowrap;
height: 3.25rem;
margin: 0.5rem 1rem;
padding: 0.5rem 1rem;
}
.label {
align-items: center;
display: flex;
flex-flow: row nowrap;
font-family: sans-serif;
font-weight: 500;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<!DOCTYPE HTML>
<html>
<body>
<div class="parent-container">
<div class="item-container">
<span class="label">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span>
</div>
</div>
</body>
</html>