.textEllipsis{
overflow: hidden;
text-overflow: ellipsis;
white-space:nowrap;
}
.wrapper{
display: flex;
width: 500px;
padding: 10px;
background: green;
}
.wrapper .main,.sub{
padding: 10px;
}
.wrapper .main{
flex: 1;
background: red;
}
.wrapper .main.widthConfig{
width: 0;
}
.wrapper .sub{
width: 100px;
flex-shrink: 0;
background: blue;
color: #fff;
}
<h3>right behavior</h3>
<div class="wrapper">
<div class="main widthConfig">
<div class="inner textEllipsis">
adfadfafasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasf
</div>
</div>
<div class="sub">
aaaaaaaaaaa
</div>
</div>
<h3>remove width: 0 get wrong behavior</h3>
<div class="wrapper">
<div class="main">
<div class="inner textEllipsis">
adfadfafasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasfafasdfasdfasdfasf
</div>
</div>
<div class="sub">
aaaaaaaaaaa
</div>
</div>
In the snippet, I create an flexBox layout with .wrapper
element.
And I add flex:1
to the .main
element, add a fixed width like width: 100px
to the sub element.
In the child element of .main
element I add some long text then the width of .main
element is out of control.
But when I add width: 0
to the .main
element everything turn right.
Can any body tell me why?