My goal is to split a div into 2 equal parts.
The problem is that when one part require wider width, the other part give in.
Note:
- the
VerylongtextVerylongtextVerylongtext
is intentionally wrapped with<div>
to simulate wrapped by a button.
stackblitz: https://jsfiddle.net/j7wd4x3k/
<div style="display: flex">
<!-- Left -->
<div style="background: yellow; flex: 1 0 0">
<div class="ellipsis">
VerylongtextVerylongtextVerylongtext
</div>
</div>
<!-- Right -->
<div style="background: red; flex: 1 0 0">
Right
</div>
</div>
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
4
Answers
Remove
flex: 1 0 0
in your CSS and replace withwidth: 50%;
– that should do the trick 🙂Using
width
onFlexbox
is not a good idea. We haveflex-basis
for it.Add
width: 50%
to your 2 child components and remove flex.Use flex when they are multiple children and want to share width equally between all child components.
You can use Bootstrap class="col-6" for two part separate, follow the bellow code example.