The Position property sets the positioning type of the element. This property defines the positioning mechanism used to establish the element layout. Any element can be positioned, but an absolute or fixed element generates a block-level box regardless of the type of element itself. The relative positioning element is offset from its default position in the normal stream.
Center up or down
div{
position:fixed;
Margin:auto;
left:0;
right:0;
top:0;
bottom:0;
width:200px;
height:150px;
}
If only need to center, then put bottom:0; or top:0; You can delete it.
If you only need to center up and down, then put the left:0; or right:0; Can
The following is a DIV element centered in the browser window
In fact, the implementation of this effect is not complicated, using CSS position positioning can be easily done. Let's take a look at the code:
<style type= "Text/css" >
dialog{
position:fixed;
_position:absolute;
z-index:1;
top:50%;
left:50%;
Margin: -141px 0 0-201px;
width:400px;
height:280px;
border:1px solid #CCC;
line-height:280px;
Text-align:center;
font-size:14px;
Background-color: #F4F4F4;
Overflow:hidden;
}
</style>
<div class= "dialog" > I was in the middle of the window, hehe! </div>
The tips for setting are all here:
. dialog{
position:fixed;
_position:absolute; /* Hack for IE6 * *
z-index:1;
top:50%;
left:50%;
Margin: -141px 0 0-201px;
width:400px;
height:280px;
border:1px solid #CCC;
line-height:280px;
Text-align:center;
font-size:14px;
Background-color: #F4F4F4;
Overflow:hidden;
}
Set position:fixed; _position:absolute;
Setting up left:50% and top:50%;
Set margin:-(div offsetwidth/2) 0 0-(Div's OFFSETHEIGHT/2)
Effect chart
The above content is small to share the CSS in the position attribute of the fixed implementation div centered all the narration, I hope you like.