CSS垂直&水平居中 [英] CSS Vertically & Horizontally Center Div

查看:123
本文介绍了CSS垂直&水平居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含ASP.NET表单的弹出窗口,单击链接请求信息,然后出现表单。

I have a pop up which contains an ASP.NET form, click the link "Request Information" and the form appears.

但是,链接请求信息触发弹出有很多内容,因此滚动是需要看到的链接。

However, the pages that have the link "Request Information" to trigger the pop up have a lot of content therefore scrolling is required to see the link.

如果用户滚动阅读内容,我需要使 div 始终居中,否则,

I need to have the div always centered if a user scrolls to read the content, otherwise if they don't scroll the pop up still appears centered on screen.

div 绝对定位,整个页面宽度是 960px ,边距设置为 0 auto

The div is positioned absolutely, the whole page width is 960px with margin set to 0 auto.

推荐答案

如果div具有固定的宽度和高度,请使用:
(如果width = 120px,height = 80px)

If the div has an fixed width and height use: (if width=120px and height=80px)

position: fixed;
top: 50%;
left: 50%;
margin-left: -60px; /* negative half of the width */
margin-top: -40px; /* negative half of the height */

这篇关于CSS垂直&水平居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆