Below is the code, two buttons in one div.
<div style="position:relative; width: 300px; height: 30px; border: 1px solid;">
<input type="button" value="ok" style="position:relative; width: 70px; height: 30px;">
<input type="button" value="ok" style="position:relative; width: 70px; height: 30px;">
</div>
How to horizontally center the buttons in fixed sized did ?
Adding text-align:center;
CSS to the <div>
will center the buttons. You should also consider separating the style from the content, which amongst other reasons, reduces the duplication. For example
div {
position:relative;
width:300px;
height:30px;
border:1px solid;
text-align:center;
}
input {
position:relative;
width:70px;
height:30px;
}
<div>
<input type="button" value="ok"/>
<input type="button" value="ok"/>
</div>
Edit: The official definition for text-align
states:
The text-align property describes how inline-level content of a block container is aligned
so it will centre all inline level elements and <input>
is an inline element.
Try this:
<div style="position:relative; width: 300px; height: 30px; border: 1px solid; text-align:center;">
<input type="button" value="ok" style="position:relative; width: 70px; height: 30px;">
<input type="button" value="ok" style="position:relative; width: 70px; height: 30px;">
</div>
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