How to centre buttons horizontally within a div element


I was struggling to find a suitable, responsive, solution for this problem that would work when the number of buttons was variable. I was fortunate enough to run across this entry which solved my problem.

<div style='display:flex;justify-content:center;'>... buttons go here ...</div>

or, if you want to use CSS:

<style>
.centredButtonHolder {
  display: flex;
  justify-content: center;
}
</style>

<div class='centredButtonHolder'>... buttons go here ...</div>

Yes, I am aware that this will work with more than just buttons, but buttons are the items I have had issues with the most.

Leave a comment