HTML
<div id="centered">
//Some Content
</div>
CSS
#centered
{
margin-left:auto;
margin-right:auto;
}
The above code is horizontally aligning irrespective of the screen size. How to vertical align the same div in center?
HTML
<div id="centered">
//Some Content
</div>
CSS
#centered
{
margin-left:auto;
margin-right:auto;
}
The above code is horizontally aligning irrespective of the screen size. How to vertical align the same div in center?
if you know the width and height of the div
then ( i have assumed it of 400 X 200), so just give negative to half values of these dimensions in margin property. you content will be centered
#centered{
position:absolute;
top:50%;
left:50%;
margin-left:-200px;
margin-top:-100px;
}
In case if your width and height are dynamic, then put this div in table
so that you can vertically and horizontally align this to middle
Try this code..
#centered
{
margin-left:auto;
margin-right:auto;
display: table-cell; // here is the trick
vertical-align:middle; // and this
height:200px;
border:1px solid blue;
}