This article mainly introduces the position attribute fixed in CSS to implement div Center-related information. if you need it, you can refer to the position attribute to specify the positioning type of the element. This attribute defines the positioning mechanism used to establish the element layout. Any element can be located, but an absolute or fixed element will generate a block-level box regardless of the element type. The relative positioning element is offset from its default position in the normal stream.
Center between top, bottom, and left
p{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; height:150px;}
If you only need to center in the left-right corner, delete bottom: 0 or top: 0.
If you only need to center up and down, set left: 0; or right: 0 ;.
The following is a DIV element that is centered in the browser window.
In fact, it is not complicated to achieve this effect. you can easily locate the position in CSS. Let's look at the code:
I am in the center of the window!
The setting tips are as follows:
.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;
Set left: 50% and top: 50%;
Set margin:-(DIV offsetWidth/2) 0 0-(DIV offsetHeight/2)
The above content is a full description of the position attribute fixed in CSS to realize p center. I hope you will like it.