0

我有一个问题,我用“位置:绝对”定位一个对话框,它工作正常,把它放在屏幕的中心。但是之后我将“位置:绝对”切换为“位置:固定”,这会导致位置不在中心。(我正在使用我拥有的最新稳定的谷歌浏览器。)

有什么诀窍让我做出这个切换时,它总是在中心?

4

1 回答 1

1

您需要使用这些样式使其看起来死心:

position:fixed;
top:50%;
left:50%;
width:400px;  /* adjust as per your needs */
height:400px;   /* adjust as per your needs */
margin-left:-200px;   /* half of width above */
margin-top:-200px;   /* half of height above */

所以position应该指定。和top应该left50%margin-leftmargin-top应该分别是盒子宽度和高度的负值的一半。

请注意,position:fixed这在 IE6 中不起作用。

于 2012-05-28T17:26:43.367 回答