Reputation: 9305
I have an input element that width is 20% and I want to center it horizontally. I have tried text-align center (parent element), but it didn't help. Here how it looks (the input box):
now the element code is like this:
<fieldset class="ui-grid-solo" style="text-align:center !important;">
<input type="number" class="answerIput"/>
</fieldset>
Is there any way to do this?
Upvotes: 1
Views: 7011
Reputation: 82337
use margins
<input type="number" class="answerIput" style="margin-left:auto;margin-right:auto;" />
Upvotes: 2
Reputation: 191819
Just add margin: 0 auto
to the element. With a fixed-width block element, automatic left/right margins will center it relative to the parent:
<input type="number" class="answerIput" style="margin: 0 auto;">
Upvotes: 4