I have 3 buttons <button class="align" id="decrease">decrease</button> <button class="align" id="reset">reset</button> <button class="align" id="increase">increase</button>
and a css class .align{ position: absolute; right: 50%; display: inline-block; }
that centers some buttons, but the end result looks like this
is there any way i could center them while keeping them seperated, or do i have to assign them each a separate class?
I expected them to be separated because of the display: inline-block;
but they just stack on top of each other. i’ve tried giving them margin but that has not worked.
3
Answers
To center the buttons while keeping them separated, you can make a slight adjustment to your CSS. You can apply text-align: center; to the parent container, and then you can set display: inline-block; on the buttons.
FYI: A quick google search / chatgpt request could’ve solved you this.
You have a lot of options, the simplest is to put
text-align:center;
on the container element – in this case<body>
– or I also show how you can get even more control – for example here I have active a grid with a small gap between each "column" and5em
width so they all take up the same space. Note16px
=1em
in most modern browsers by default but I set it as a base anyway. So5em
would be 5 X 16 = 80pxNOTE: on BOTH these you can remove the
.align{ display: inline-block; }
but that was your question thus I left that in.simplest option:
You can align the three buttons with just a flex parent container: