Take situation that we have a dive with fixed width say 300px, and we want to position it from top say 150px and we want this div to be positioned in horizontal center.
What I do for this is that I take one outer div, give it absolute position, top 150px and width 100%; then I make another div inside the previous one, and give it width as we wanted 300px, position relative to outer div and left and right margins set to auto. So now outer div makes vertical position alignment and is used also for inner div's relative left and right auto margin calculation.
So here's the code:
<style type="text/css">
.outerDiv
{
top: 150px;
position: absolute;
width: 100%;
text-align: center;
}
.innerDiv
{
margin-left:auto;
margin-right:auto;
position: relative;
width: 300px;
background-color: black;
}
</style>
...
<div class="outerDiv">
<div class="innerDiv">
inner div content
</div>
</div>
