views:

40

answers:

2

Hello, I have a div with several images inside, and I would like to center this vertically. I can give a specific width and height do the div. No prob. I also accept js if I must to. I'm just wondering, from the MAZE of those examples, can I have a simple one.

The div as width of 600 and height of 500.

Thanks in advance, MEM

+3  A: 

Easy peasy. Say your div has id="myDiv". Then...

#myDiv {
    position: absolute;
    top: 50%;
    margin-top: -250px; // half the height of #myDiv
}

...will center the div inside of its offset parent.

Half-scale demo (so that you don't have to make your window really big to properly see the effect)

Matt Ball
Yup. And the same will fit for the horizontal side. ;) thanks.
MEM
@MEM: it's actually even easier to center a fixed-width `div` horizontally. Just give it `margin-left: auto; margin-right: auto;`.
Matt Ball
A: 

Handle this problem simply, you can use padding to the div.

Mubeen
No I can't. :) At least not a fixed value.
MEM