Centering elements in jQuery Mobile

gruner picture gruner · Dec 1, 2010 · Viewed 103.8k times · Source

Does the jQuery Mobile framework have a way of centering elements, specifically buttons? It looks like it defaults to left-aligning everything and I can't find a way (within the framework) to do this.

Answer

naugtur picture naugtur · Dec 9, 2010

jQuery Mobile doesn't seem to have a css class to center elements (I searched through its css).

But you can write your own additional css.

Try creating your own:

.center-button{
  margin: 0 auto;
}

example HTML:

<div data-role="button" class="center-button">button text</div>

and see what happens. You might need to set text-align to center in the wrapping tag, so this might work better:

.center-wrapper{
  text-align: center;
}
.center-wrapper * {
  margin: 0 auto;
}

example HTML:

<div class="center-wrapper">
  <div data-role="button">button text</div>
</div>