Say I have a div on my page as:
<div class="center"></div>
My CSS looks something like:
.center{
background:red;
position:absolute;
left:50%;
top:50%;
margin-left: ?
margin-top: ?
}
So as you can see above, the only thing that I need to know is how to set margin-left
and margin-top
values. If I had a known width and height of .center
div (say 300px each), I would have set margin-left
and margin-top
values as half of that value (-150px both)
But my question is how do I set those values if width/height of .center
div is unknown (or say it's dynamic)?
Can I use some kind of CSS expression OR does that have cross-browser limitations? What's the best way to do this?