vlio20
vlio20

Reputation: 9305

How to center element in jquery mobile

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):

enter image description here

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

Answers (2)

Travis J
Travis J

Reputation: 82337

use margins

<input type="number" class="answerIput" style="margin-left:auto;margin-right:auto;" />

Upvotes: 2

Explosion Pills
Explosion Pills

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

Related Questions