I have 3 DIV components where:
.child-left: aligns its contents to the left on the screen.child-center: aligns its contents to the center on the screen.child-right: aligns its contents to the right on the screen
However, when the contents (or text) get really long in .child-center, the contents overflow each other even though it has its own width. Please see the below screenshot:
I'd like to know:
- Why the content (
Long text...) in.child-centerdoes not fit within the width? - How do I fix the issue with the minimal changes? (I'd like to keep using
display: flex, I DO NOT want to usetext-align: center)
What I want to achieve is this:
Please help me out!
Code:
.parent {
display: flex;
align-items: center;
width: 100%;
}
.child-left {
display: flex;
justify-content: flex-start;
width: 20%;
background-color: green;
white-space: nowrap;
}
.child-center {
display: flex;
justify-content: center;
width: 60%;
background-color: red;
white-space: nowrap;
}
.child-right {
display: flex;
justify-content: flex-end;
width: 20%;
background-color: yellow;
white-space: nowrap;
}
<div class="parent">
<div class="child-left">
<span>11111111111111111111111111</span>
</div>
<div class="child-center">
<span>Long text Long text Long text Long text Long text Long text Long text Long text Long text</span>
</div>
<div class="child-right">
<span>22222222222222222222222222</span>
</div>
</div>

