0

Possible Duplicate:
How to make an image center (vertically & horizontally) inside a bigger div

I am trying to make an image gallery on my website, but I cannot center the image inside the div.

The CSS for the div is:

#animation
{
display : none;
position: absolute;
z-index:1;
background : rgba(0,0,0,0.7);
height: 100%;
width: 100%;
border: 0px;
}

And the image id is:

#pictures
{
...
}
Community
  • 1
  • 1
southpaw93
  • 1,891
  • 5
  • 22
  • 39
  • duplicate of [http://stackoverflow.com/questions/388180](http://stackoverflow.com/questions/388180/how-to-make-an-image-center-vertically-horizontally-inside-a-bigger-div) – RAN Jul 29 '12 at 17:27

5 Answers5

2

One way to do it is a table cell display and vertical align: middle;

Fiddle

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Andy
  • 14,427
  • 3
  • 52
  • 76
  • 1
    what about horizontal aligning – bugwheels94 Jul 29 '12 at 17:18
  • 2
    My fiddle includes that too, I used `margin: 0 auto;` (this only works if you declare the image as a block level element (`display: block;`) – Andy Jul 29 '12 at 17:19
  • yeah , I tried this but the things is that when I declare table cell the div will not take the (display:none) and the div won't hide. – southpaw93 Jul 30 '12 at 11:22
  • I cant help much without context, but you could try visibility: hidden, or absolute position and throw the image off the screen with a -value on left: – Andy Jul 30 '12 at 11:24
0

margin:auto; add autommatic margin and center the image have a try, but I need more code , could you post it?

Xenione
  • 2,174
  • 1
  • 23
  • 30
0

Put your image inside div and center it like this: Fiddle here

 div{
 width:300px;
 height:300px;
 margin:0px auto;
 margin-top:30px; //to pull it down
 }
Dejo Dekic
  • 2,088
  • 4
  • 27
  • 50
0
margin:auto;

it will automatically center your div by adding equal margin to the left and right of your div block element

0

Check out these resources:

If you know the width of the div - How to make an image center (vertically & horizontally) inside a bigger div

If you don't know the width of the div - http://doctype.com/css-centering-wide-image-unspecified-dimensions-div-unspecified-dimensions

Community
  • 1
  • 1
Freddy
  • 442
  • 1
  • 6
  • 13