码迷,mamicode.com
首页 > 其他好文 > 详细

弹层相对于浏览器窗口(或屏幕)居中

时间:2017-06-20 16:29:09      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:dex   浏览器   dom   top   attribute   width   osi   ret   元素   

三、弹层相对于浏览器窗口(或屏幕)居中:

可将弹层对应的dom作为body第一层子元素,然后给弹层设置样式:

{   background-color: #fff;
    left: 50%;
    margin: -高/2 0 0 -宽/2;
    position: fixed;
    top: 50%;
    width: 300px;
    height: 300px;
    z-index: 25;
}
PS:
1、margin的值设置: -(元素的实际高度/2) 0 0 -(元素的实际宽度/2);
2、该元素的宽高如果被内部元素撑开,也可不写;

弹层相对于浏览器窗口(或屏幕)居中

标签:dex   浏览器   dom   top   attribute   width   osi   ret   元素   

原文地址:http://www.cnblogs.com/sharestone/p/7054456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!