我有一个弹出窗口,其中包含一个ASP.NET表单,点击“请求信息”链接即可显示该表单。
然而,具有触发弹出窗口的“请求信息”链接的页面有很多内容,因此需要滚动才能看到链接。
如果用户滚动以阅读内容,则需要始终将
然而,具有触发弹出窗口的“请求信息”链接的页面有很多内容,因此需要滚动才能看到链接。
如果用户滚动以阅读内容,则需要始终将
居中,否则,如果他们不滚动,则弹出窗口仍将居中显示在屏幕上。
被绝对定位,整个页面宽度为960px,边距设置为0 auto。
position: fixed;
top: 50%;
left: 50%;
margin-left: -60px; /* negative half of the width */
margin-top: -40px; /* negative half of the height */
这是你想要做的吗? http://jsfiddle.net/Hrwf8/
关键是将左边和顶部样式设置为50%,并将margin-left和top设置为div宽度和高度的一半的负数。当然,这需要你的div有一个固定的大小。
.ClassCenter {
position: absolute;
left: 50%;
top: 50%;
}
来源: http://demo.tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/demo.html
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto; /* this requires a fixed size */