I have a container with flex
. I wanted middle child to fill all possible width with flex-grow: 1
. But if there is a huge content even with overflow: hidden
, it goes out of the max-width
of container
.
max-width: 100%
for middle element works (sets the width strictly) but I can't use that, because I have side elements that can have different widths from time to time.
.container {
max-width: 300px;
height: 90px;
background-color: red;
display: flex;
}
.item-x {
min-width: 42px;
height: 100%;
background-color: green;
}
.item-y {
margin: 10px;
padding: 10px;
flex-grow: 1;
background: purple;
}
.item-y-inner {
background: orangered;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<html lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<title>example</title>
</head>
<body>
<div class="container">
<div class="item-x">X</div>
<div class="item-y">
<div class="item-y-inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut cursus,
dolor ac volutpat porta
</div>
</div>
<div class="item-x">X</div>
</div>
</body>
</html>
How to say middle element to fill all possible space but not greater than parent container width - side container widths