1

I got some images in a div:

<div>
    <img src="1.png">  </img>
    <img src="1.png">  </img>
</div>

And this in browsers is:

-----------------
|XX             |
-----------------

and I want to these images to be located in the center of the div, that is to say, like this:

-----------------
|      XX       |
-----------------

How to do that?

PS: Maybe this question is just very trivial, but I'm a newbie in CSS/HTML and I just can't overcome.

Sayakiss
  • 6,668
  • 8
  • 53
  • 102
  • possible duplicate of [CSS - center image using text-align center?](http://stackoverflow.com/questions/7055393/css-center-image-using-text-align-center) – Chango May 26 '13 at 07:50

4 Answers4

3

For images, a simple text-align: center would suffice.

http://jsfiddle.net/G57zL/1

casraf
  • 19,496
  • 7
  • 52
  • 86
2
div {
    text-align: center;
}

Demo here: http://jsfiddle.net/Wc8kz/

And only one suggestion: img is self-closing tag and should be defined as <img src="..." /> or even <img src="..."> in HTML5. Code <img src="..."></img> is not valid.

Jan.J
  • 2,990
  • 1
  • 22
  • 32
2

Right way to do it according to W3c

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

Fiddle

PSL
  • 122,084
  • 19
  • 250
  • 241
1

Css

div.centered{
    text-align:center;
}

HTML

<div class="centered">
    <img src="1.png" />
    <img src="1.png" />
</div>

DEMO

The Alpha
  • 138,380
  • 26
  • 281
  • 300