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,878
  • 8
  • 61
  • 107
  • 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
  • 21,085
  • 9
  • 56
  • 91
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
  • 3,050
  • 1
  • 23
  • 33
2

Right way to do it according to W3c

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

Fiddle

PSL
  • 123,204
  • 21
  • 253
  • 243
1

Css

div.centered{
    text-align:center;
}

HTML

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

DEMO

The Alpha
  • 143,660
  • 29
  • 287
  • 307