How do you center a button in css if display is inline? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How do you center a button in css if display is inline?

I tried margin: auto; but it didn't work. I tried margin-left: auto; margin-right: auto;

16th Mar 2017, 8:49 PM
Andrew Harris
Andrew Harris - avatar
4 Answers
+ 4
try align: center;
18th Mar 2017, 11:39 AM
Yash Gohel
Yash Gohel - avatar
+ 2
if you know differences between inline elements and block level elements, you would understand it. anyway button is inline. to make button act like block, just add ur css display: block; <style> body{ border: 1px solid red; } button{ width: 100px; height: 30px; line-height: 30px; text-align: center; display: block; margin: 0 auto; border: 1px solid red; } </style> <button>Click Here</button> <button>Click Here</button> if you remove the display attributte, you'll understand the difference.
17th Mar 2017, 12:32 AM
M Omar
M Omar - avatar
0
use <center> tag <center> statement </center>
17th Mar 2017, 8:57 AM
Kajal
Kajal - avatar
0
<center>........</center>
17th Mar 2017, 11:40 AM
YAZAN AHMED
YAZAN AHMED - avatar