`
wyzxzws
  • 浏览: 378836 次
  • 性别: Icon_minigender_1
  • 来自: dazhou
社区版块
存档分类
最新评论

ie6绝对居中彻底解决

 
阅读更多

代码:

css

.center {
    position: fixed;
    *position: fixed;
    _position: absolute;
    display: block;
    width: 700px;
    min-height: 80px;
    z-index: 998;
    background-color: #fff;
    border: 1px #d7d7d7 solid;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: 0 5px 5px #d7d7d7;
    -moz-box-shadow: 0 5px 5px #d7d7d7;
    box-shadow: 0 5px 5px #d7d7d7;
    top: 50%;
    left: 50%;
    _top: expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight/2-this.offsetHeight/2-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
}

 js

   

高级浏览器ie8+,firefox,chrome,opera,safari
center.css({"margin-left": "-350px", "margin-top": (-1 * pos.height() / 2) + "px"});

 

ie6、7
center.css({"margin-left": (-1 * pos.width() / 2) + "px", "margin-top": (-1 * pos.height() / 2) + "px"});

 注:如果center宽度为百分比,照样适用,只是

高级浏览器ie8+,firefox,chrome,opera,safari
center.css({"margin-left": "center百分比宽度/2", "margin-top": (-1 * pos.height() / 2) + "px"});

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics