码迷,mamicode.com
首页 > Web开发 > 详细

css3 position fixed居中的问题

时间:2014-06-02 23:00:57      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   a   

通常,我们要让某元素居中,会这样做:

#element{
margin:0 auto;
}


如果还想让此元素位置固定呢?一般我们会添加position:fixed,如下:

#element{
position:fixed;
margin:0 auto;
}


但是这样做的结果就是,元素不居中了。这说明fixed使对象脱离了正常文档流

解决方案:

#element{
position:fixed;
margin:0 auto;
left:0;
right:0;
}

但是在IE7以下的版本中无法工作,要将其更改为:

#element{
position:fixed;
margin:0 auto;
left:auto;
right:auto;
}

最后我们可以这样:

if ($.browser.msie && parseInt($.browser.version, 10) <= 7) {
    strAlertWrapper.css({position:'fixed', bottom:'0', height:'auto', left:'auto', right:'auto'});
 }
示例代码:http://jsfiddle.net/4Ly4B/33/
如果对你有帮助,欢迎加入:QQ群:124116463,一起讨论前端技术吧!






css3 position fixed居中的问题,布布扣,bubuko.com

css3 position fixed居中的问题

标签:c   style   class   blog   code   a   

原文地址:http://blog.csdn.net/xiebaochun/article/details/27679023

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