I'm trying to create a layout where the grandparent div has multiple parent divs, each with different numbers of elements. In one type of parent div with 3 elements, the second element should always be aligned in the center. The first and third elements in this type of parent div need to touch the second element and adjust towards the edges only if their content increases. I want to achieve this using CSS without messing up the relationship between these elements. Most online solutions suggest using margins or absolute positioning, but they disrupt the alignment between the elements.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="grandparent">
<div class="parent">
<span class="left-side">First Text!</span>
<span class="must-be-centered">SOME TEXT!</span>
<span class="right-side">Other Text!</span>
</div>
<div class="parent">
<span class="must-be-centered">SOME TEXT!</span>
</div>
</div>
https://i.sstatic.net/vU0zM.png
The important thing is that the large yellow element in the center is perfectly centered, while the left and right elements are touching it. Even in the div with just one element, the single element remains centered.