css:fixed定位兼容不同系列不同版本的瀏覽器包括IE6.0
現在很多門戶網站頁面內容龐大,都會往下拉很長, 在以前我們想回頂部的時候要不斷往上滾動鼠標的滾輪,直到滾到頂部為止,現在如果大家細心觀察右下角是不是有一個點擊回到頂部的按鈕呢,對, 今天我要說的就這個按鈕的布局,閑話不多說,直接上代碼,在代碼中我盡量的標注css樣式,以方便大家閱讀;
復制代碼代碼如下:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml"
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /
titlefixed定位,解決IE6閃動問題/title
style type="text/css"
*html{
background-image:url(about:blank);
background-attachment:fixed;
}/*此代碼解決IE6.0下不會出現閃動*/
.backgroundBox {
border:1px solid orange;
width:100px;
height:2000px;
}
.fixedBox {
border:1px solid red;
width:100px;
height:100px;
position:fixed; /*支持實現w3c標準的瀏覽器*/
_position:absolute; /*單獨針對IE6*/
left:200px; /*距離頂部200px*/
top:200px; /*距離右邊200px*/
_top:expression(eval(document.documentElement.scrollTop 200)); /* 200是IE6.0下面距離瀏覽器窗口頂部的位置*/
/*IE6.0下面距離底部位置為0px*/
/*_top:expression(eval(document.documentElement.scrollTop document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));*/
}
/style
/head
body
div class="backgroundBox"/div
div class="fixedBox"fixed box/div
/body
/html
