I'm using this snippet of code from here (shown below) to horizontally align items in a list group (in Bootstrap 4).
.list-group.list-group-horizontal{
display: flex;
flex-direction: row;
}
.list-group.list-group-horizontal .list-group-item {
margin-bottom: 0;
margin-right: 0;
border-right-width: 0;
}
.list-group.list-group-horizontal .list-group-item:first-child {
border-top-right-radius:0;
border-bottom-left-radius:4px;
}
.list-group.list-group-horizontal .list-group-item:last-child {
border-top-right-radius:4px;
border-bottom-left-radius:0;
border-right-width: 1px;
}
How can I center align the list group? I tried adding class text-center and some other things, however I did not succeed.
<div id="app" class="container my-container">
<!-- Header -->
<h2 class="text-center" >Sample Header</h2>
<!-- Buttons -->
<div class="list-group list-group-horizontal">
<a href="#" class="list-group-item active">Categories</a>
<a href="#" class="list-group-item">Search</a>
</div>
</div>
Codepen
For posterity:
Apply d-flex justify-content-center if your element is not a flex element.
Original Answer:
Apply justify-content-center to the list-group
Codepen: https://codepen.io/anon/pen/gZRzOR
Here it is in the documentation: https://getbootstrap.com/docs/4.0/utilities/flex/#justify-content
<div class="list-group list-group-horizontal justify-content-center">
....
....
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With