完美的IE6 position:fixed

这个内容是老生常谈了,主要问题就是IE6不支持 position:fixed 引起的BUG.当我们去搜索解决这个bug的垮浏览器解决办法时,绝大多数结果都是说使用 position:absolute 来替代解决,可是我们真的解决了么?没有,因为当页面比较长的时候,拖动滚动条,那个fix的地方也相应的闪动.虽然最终会近似于需求的目标,但是不完美.那么如何解决这一问题呢?

造成这个问题的原因是fixed元素的绝对位置是相对于HTML元素,滚动条是body元素的(貌似ie6中他们的区别就是在于滚动条界限那里).
知道了原因,我们就大概知道如何解决了:

 

 
  
<!--[if IE 6]>
<style type="text/css">
html
{ overflow : hidden ; }
body
{ height : 100% ; overflow : auto ; }
#fixed
{ position : absolute ; }
</style>
<!--[endif]-->

没错,就是加上这样的一段code,现在看看完整的页面code:

 

 

代码
 
   
<! 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" />
< title > IE6 position:fixed </ title >
< style >
*
{
padding
: 0 ;
margin
: 0 ;
}

#fixed
{
background-color
: #ddd ;
border
: 1px solid #aaa ;
position
: fixed ;
right
: 0 ;
top
: 0 ;
}
</ style >
<!-- [if IE 6]>
<style type="text/css">
html{overflow:hidden;}
body{height:100%;overflow:auto;}
#fixed{position:absolute;right:17px;}
</style>
<!--[endif]
-->
</ head >
< body >
< div style ="height:2000px" ></ div >
< div id ="fixed" >
FIXED
</ div >
</ body >
</ html >

 

 

转载于:https://www.cnblogs.com/xylxq1925/articles/1901400.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值