h_a86
h_a86

Reputation: 772

How do I center an image using jqmobile

Hi i am using this piece of code to center image in jquery mobile, it centers the image in iphone simulator but when i check it on iphone, it did not exactly centers (centers itself but not exactly) itself but tends towards left.

<div data-role="content" data-theme="a">

   <div id="logo_image">
       <img src="images/logo.png"  alt="Image Header" >
   </div>

</div>

and the css is

#logo_image {
  text-align: center;
  margin-left:0 auto;
  margin-right:0 auto;
}

Thanks in advance...

Upvotes: 4

Views: 13050

Answers (3)

shanabus
shanabus

Reputation: 13115

These other answers are partially correct, but in order for the margin: 0 auto properties to work, I believe you also have to specify a width for your element.

Something like this:

#logo_image {
  text-align: center;
  margin-left:0 auto;
  margin-right:0 auto;
  width: 80%; 
}

Upvotes: 2

Razz
Razz

Reputation: 4005

Try to add diplay: block to your image it should position it right.

Upvotes: 2

CyrillC
CyrillC

Reputation: 557

just try margin: 0 auto instead of left & right margin. you'll be able to set the top and bottom margin afterwards. greets

Upvotes: 5

Related Questions