I'm trying to center a pair of buttons within a form. These buttons are wrapped in <div>
which has display: inline-block
set against it so the <div>
is only as wide as the buttons. The parent to the <div>
which is a <form>
element has fixed-width: 290px
set against it.
However, on the <div>
, when I set margin-left: auto; margin-right: auto
, the <div>
doesn't center itself within the <form>
. I have even set display: block
against the <form>
element too to no avail.
What am I doing wrong?
HTML:
<form id="schemeForm">
<!--Other HTML elements-->
<div id="formButtons">
<input type="button" value="Back" />
<input type="submit" value="Submit" />
</div>
</form>
CSS:
#schemeForm {
width: 290px;
display: block;
}
#formButtons {
display: inline-block; /*to make it only as wide as buttons*/
margin-left: auto;
margin-right: auto;
}
Example Code Snippet:
#schemeForm {
width: 290px;
display: block;
background-color: black;
}
#formButtons {
display: inline-block; /*to make it only as wide as buttons*/
margin-left: auto;
margin-right: auto;
background-color: orange;
}
<html>
<body>
<form id="schemeForm">
<!--Other HTML elements-->
<div id="formButtons">
<input type="button" value="Back" />
<input type="submit" value="Submit" />
</div>
</form>
</body>
</html>