views:

47

answers:

1

Hello!

How can I align text in the vertical middle of a Div element provided it has a position:absolute property specified?

Setting display:table-cell; vertical-align:middle; isn't working.

Thanks!

+1  A: 

Wrap an inner div and give it position:relative; top:-50%; in addition to giving the absolute a top:50%.

Though of course if it's complicated styling, please provide your CSS.

You can get away with line-height if it's just a single line of text, you'd have to kill the absolute rule though.

meder
Thank you both for your replies. My code is as follows:body > div (absolute positioning with margin:0 auto; for centering > div with position absolute (repeating element) > other tags + the div I want to have vertically centered text in. It also has absolute positioning.It has an unknown number of lines of text. It has top:0 and bottom:0 so that it is as high as it's parent div.Looks complicated... sorry.
Francisc