views:

53

answers:

2

I don't know and can't possibly know the width of the absolute div I need centered. It must to be absolutely positioned because it is overlapping other elements (z-index trickery). This is my basic structure

<div style='position:relative'><div></div><div style='position:absolute'>...</div></div>

The first child div is not absolutely positioned so as to lend its height and width to the parent. The second div must overlap its siblings and be centered horizontally.

The above structure is just an illustration of my dilemma, in reality the parent div will have many children, not all of them will be divs, none of their dimensions will be known.

Thank you, I'm going to sleep now...

A: 

Although this is deprecated, <div align="center"> should work.

Syd
+2  A: 

Well, I don't think that is posible to do that using only CSS because to center an absolute div you always need to have the width set in order to use -> "left: 50%; margin-left: [width/2]px;".

Anyway, you can use some javascript/jQuery code do get the width of your div and then dinamicaly set the CSS width property.

Please read the folowing: http://api.jquery.com/width/ http://api.jquery.com/css/#css2

Pedro Oliveira