I am wondering how can I make some buttons to stack vertically and not horizontally in css.
So, the html would be like:
<button>Test<button>
<button>Test<button>
<button>Test<button>
And those buttons will by default stack horizontally, what I want is to make them stack vertically (so everyone's on top of the next button).
Use the . btn-group-vertical class in Bootstrap to make a button group appear vertically stacked.
Other than flexbox property, we can also center align the button horizontally and vertically using a set of CSS properties. Add position: relative to the container class and position: absolute to the class containing the button. Now use left:50% and top:50% to position the button to the center of the container.
Add button { display: block; } to your CSS. Buttons by default are inline elements, which will stay on the same line when possible. block elements on the other hand (like divs), will be forced to a new line.
You can wrap the buttons with container divs and leverage Flexbox to justify the contents in the center. It's important to give the buttons the same size, so that they align properly, and scale the containing divs accordingly so that the buttons don't overflow or wrap.
Define the buttons as block-level elements. Also, note the use of the correct closing tag (</button>
):
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
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