How to center a button using CSS?

Button is an inline element. It can not be centered using the “margin:auto;” that is for block element. Even if you set “display:inline-block” for it, the “margin:auto;” still has no effects. You can set “display:block” for it to change it to a block element and center it with “margin:auto;”.

Don’t try to use “text-align:center” for the button as it is used to center the text on the button rather the button itself. You can, however, apply “text-align:center” to the parent block element of the button to center the button. It is a little unnatural because “text-align:center” is for text in the literal meaning. But it can also be used to center the inline elements such as button contained in it.

Other methods for centering a button include applying the relative positioning to the button, together with the margin-left or transform:translateX(-50%) properties.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Comments are closed, but trackbacks and pingbacks are open.