With utilising d-flex
, justify-content-center
and flew-grow-1
, I achieved the desired result with 3 divs.
<div class="row bg-primary d-flex justify-content-center">
<div class="col-auto">
LEFT
</div>
<div class="col-auto flex-grow-1 text-center">
Middle
</div>
<div class="col-auto">
Right
</div>
</div>
I want to achieve the same effect with 2 divs while Middle one is forced to be the exact center. However, if I try to remove the 'Right' element, it can't calculate the center.
<div class="row bg-primary d-flex justify-content-center">
<div class="col-auto">
LEFT
</div>
<div class="col-auto flex-grow-1 text-center">
Middle
</div>
</div>
Is there a way to force "Middle" to be exact center and Left or Right divs take space from Middle as they need? Kind of like all the positions of Left and Middle are same as in the first image but 'Right' div is not there.
Fiddle http://jsfiddle.net/4a7tLf0m/
I can achieve the same effect with giving specified column size (col-3
instead of col-auto
) but I don't like the fact that I need to be explicit. Is this the only way to go?