html - 弹出窗口未分配屏幕中心

标签 html css

我正在使用下面的代码来分配屏幕的弹出窗口。但它不起作用。弹出窗口根据 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;
}

最佳答案

试试这个:

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

这将缩放您的弹出窗口,并为其指定尺寸。 当您的容器是绝对的时,您无需提供边距:顶部、右侧、左侧、底部值即可。

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

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

关于html - 弹出窗口未分配屏幕中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331423/

相关文章:

css - Less mixin 可以对某些元素类型应用特殊规则吗?

html - 我的代码有什么问题 [CSS]

html - 使用 Bootstrap 3.1.1 Glyphicons - Firefox 只显示一个看起来像 fork 的奇怪图标?

javascript - 垂直对齐问题

javascript - 为什么 session ID 不保留在同一域中

javascript - Firefox 中的 body 最大高度

css3不同状态的不同关键帧

html - CSS :after content and absolute position for button makes it not clickable

html - Bootstrap 导航栏错误 : Allows text below it to show when the navbar is expanded

javascript - DOM 类名称不适用于按钮