CSS Vertically & Horizontally Center Div
This question already has an answer here:
如果div具有固定的宽度和高度,请使用:(如果width = 120px和height = 80px)
position: fixed;
top: 50%;
left: 50%;
margin-left: -60px; /* negative half of the width */
margin-top: -40px; /* negative half of the height */
If your popup div has a fixed size then you can use this CSS:
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto; /* this requires a fixed size */
Otherwise you have to fiddle around with display: table-cell; and the like.
Is this what you're trying to do? http://jsfiddle.net/Hrwf8/
The key here is to set the left and top styles to 50% and set the margin-left and top to the negative amount of half of the width and height of the div. This of course requires that you have a fixed size for your div.
链接地址: http://www.djcxy.com/p/41644.html上一篇: 在<DIV>中垂直居中文本
下一篇: CSS垂直和水平中心Div