Reputation: 6045
Is there any way to left-align, center-align, and right-align elements on the same line without separating the elements into separate containers. To right-align an element, I know I can float the element by using pull-right
directly on the element; but I'm having trouble centering an element. I'm using bootstrap but a pure css solution would be fine as well.
In other words, I know this works: https://jsfiddle.net/u69rz06s/3/
<div class="row">
<div class="col-xs-4">
<button>Button 1</button>
</div>
<div class="col-xs-4 text-center">
<button>Button 2</button>
</div>
<div class="col-xs-4 text-right">
<button>Button 3</button>
</div>
</div>
But I looking for a solution that looks something like this (however, this currently does not work): https://jsfiddle.net/pvw1qL5v/2/
<div class="col-xs-12">
<button>Button 1</button>
<button style="text-align: center;">Button 2</button>
<button class="pull-right">Button 3</button>
</div>
Upvotes: 0
Views: 101
Reputation: 7295
Use display: flex
and justify-content: space-between
.
.col-xs-12 {
display: flex;
justify-content: space-between;
}
<div class="container">
<div class="row">
<div class="col-xs-12">
<button>Button 1</button>
<button>Button 2</button>
<button>Button 3</button>
</div>
</div>
</div>
Upvotes: 2