您當(dāng)前位置:圖趣網(wǎng)(Tuquu) >> 網(wǎng)頁設(shè)計(jì)教程 >> 移動(dòng)前端 >> 瀏覽設(shè)計(jì)教程

網(wǎng)頁前端 - 解決IE6不支持position:fixed的問題

 

前段時(shí)間因?yàn)楣镜哪硞€(gè)項(xiàng)目需要用到底部固定元素在網(wǎng)頁中隨著瀏覽器滾動(dòng)而滾動(dòng),當(dāng)然用position:fixed這個(gè)屬性來做,可是問題來了,IE6.0下面不支持position:fixed這個(gè)屬性。

在網(wǎng)上查找資料,實(shí)踐,最終OK了,貼出來大家分享。

當(dāng)然,在IE6以上版本,火狐,谷歌等瀏覽器都是件容易的事情,直接用position:fixed這個(gè)屬性就可以搞定。如:

.top {position:fixed;bottom:auto;top:0px;} /* 頭部固定 */
.bottom {position:fixed;bottom:0px;top:auto;} /* 底部固定 */
.left {position:fixed;right:auto;left:0px;} /* 左側(cè)固定 */
.right{position:fixed;right:0px;left:auto;} /* 右側(cè)固定 */

但在IE6及以下版本這樣設(shè)置是沒用的,要設(shè)置成這樣:

body{background-image:url(about:blank);background-attachment:fixed;} /* 修正IE6振動(dòng)bug */
.top {position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));} /* IE6 頭部固定*/
.left{position:absolute;left:auto;right:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt

(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));} /* IE6 右側(cè)固定 */
.right {position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt

(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));} /* IE6 右側(cè)固定 */
.bottom {position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt

(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));} /* IE6 底部固定 */

不知道對(duì)你有沒有幫助呢?

[教程作者:admin]
免責(zé)聲明:本站文章系圖趣網(wǎng)整理發(fā)布,如需轉(zhuǎn)載,請(qǐng)注明出處,素材資料僅供個(gè)人學(xué)習(xí)與參考,請(qǐng)勿用于商業(yè)用途!
本文地址:http://irelandcustomcontracting.com/tutorial/wd1514.html
網(wǎng)頁前端開發(fā) - CSS ::Selection
網(wǎng)頁前端 - select的最佳預(yù)設(shè)(reset)
圖趣網(wǎng)微信
建議反饋
×