弹出窗口不指定屏幕的中心

时间:2013-03-11 04:54:02

标签: html css css3

使用以下代码分配弹出窗口的确切中心。但它不起作用。弹出窗口根据div的大小出现在不同的位置。但我想在屏幕中央显示div。

.pnl_renewal_res
{   
    background:White;
    position: absolute;
    top: 50%;
    left: 50%;
    margin:-50px 0 0 -100px; /* [-(height/2)px 0 0 -(width/2)px] */
    display: none;
    border:1px solid  #333333;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

.pnl_renewal_res
{   
    background:White;
    position: absolute;
    top: 30%;
    left: 30%;
    right:30%;
    bottom:30%;
    display: none;
    border:1px solid  #333333;
}

这将缩放您的弹出窗口,并为其提供尺寸。 当您的容器是绝对容器时,您不需要提供保证金:top,right,left,bottom值。

如果要更改弹出窗口的高度和宽度,请更改百分比值。

此外,您可以结合使用heightwidth以及topleft