Bootstrap buttons are no different from any other DOM elements of an HTML document. Aligning them is more likely the same as aligning paragraphs, divs and sections. Here are some of the scenarios that one can encounter.
- Buttons in ‘container’ class:
Buttons in ‘container’ class can be aligned with the ‘text-align’ properties. Wrap the group of buttons inside a div and align them using the following classes,
Note: You can also use HTML5 <center> tag to align buttons to the center.
- Buttons inside FlexBox:
- .d-flex .flex-row
- .d-flex .flex-column
Another way of arranging buttons is by using flex-utilities. The basic flex classes provided by Bootstrap are
The following pattern can be achieved by choosing either one of them.
- Relative-Absolute method:
This is the most used method present online. In this case, the parent div is assigned a position ‘relative’ while the child divs are assigned position ‘absolute’.
Elements inside ‘absolute’ divs can be aligned in whatever way you want. Consider the following example. It shows all possible alignments a DOM element, in this case, buttons can have.