user4698001
user4698001

Reputation:

How img can be centered?

I have a img which I need for centering, I try margin: 0 auto; but still can't center the img. How can I?

Thank you

<div>
    <img src="../p66.jpg" />
</div>

div{margin:0 auto;width:100%;}
img {margin:0 auto;}

Upvotes: 2

Views: 35

Answers (2)

Kirs Kringle
Kirs Kringle

Reputation: 929

So you can do something like this...

CCS

img.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

HTML

<img src="blwebcam-sample.jpg" alt="Suni" class="center" />

I found this searching Google.

Source: http://webdesign.about.com/od/beginningcss/a/aa012207.htm

Upvotes: 1

sinisake
sinisake

Reputation: 11328

div{margin:0 auto;width:100%;text-align:center;}

You can use text-align: center in container, if you don't have img width. Otherwise, if you set image width, and display: block, margin:0 auto on image will work...

E.g. img {margin:0 auto;display:block;width:100px}

Upvotes: 1

Related Questions