当ie7不认!important之后 [布局的解决办法]

2022-01-11,,,,

在IE7之前,我们在布局时常用!important来解决IE和FF之间的差别; 但是在IE7出来之后,!important对IE7就不起作用了,而有些时候IE7的解释方法又与FF和IE6不同;这时新的问题就出现了;用!important可以解决IE6但是解决不了IE7; 这样在不同的浏览器中看到的同一个网页的效果就不同了;

这是前天作布局时的一个问题;可以先看一下效果;http://www.zishu.cn/blogview.asp?logID=553 

或者运行一下下边的代码也可以同样看到效果:
复制代码 代码如下:

zishu.cn test

body{ font-size:12px; line-height:1.8; font-family:Verdana, "宋体", Arial,Sans; text-align:center; background:#FFF; color:#666; margin:50px; padding:0; list-style:none; }
a:link,a:visited{color:#000099; text-decoration: underline;}
a:hover,a:active{color:#000;text-decoration: none;}
#zishu_test li{ float:left; width:14%;text-align:center; margin:0 auto; list-style:none }
#zishu_test li a{border-right:1px solid #fff;border-bottom:1px solid #fff; width:100px; height:110px; background:#fff;display:block; padding-top:10px; margin:auto}
#zishu_test li img{ width:75px; height:75px; display:block; text-align:center; margin:auto; background:#FFF; padding:3px; border:1px solid #D8A18B;}
#zishu_test li span{display:none;}
#zishu_test li a:hover span{ margin-top:-10px;display:block; border-bottom:1px solid #666; border-right:1px solid #666; background:#FA9000; width:100px; color:#FFF; position:absolute; } 
* html #zishu_test li a:hover span {margin-left:-8px; } /* IE6 */ 
*+html #zishu_test li a:hover span {margin-left:-8px; }/* IE7*/ 
#zishu_test li a:hover{ border-right:1px solid #D8A18B;border-bottom:1px solid #D8A18B; width:100px; height:110px; background:#F5F5F5;display:block; padding-top:10px;} 

  

        

  • 64d / 47 hitspixu
  •     

  • 24d / 35 hits秀才
  •     

  • 66d / 87 hits透露
  •     

  • 40d / 34 hitsLIVID
  •     

  • 47d / 56 hits老孟
  •     

  • 42d / 36hits小玉
  •     

  • 63d / 67 hitspixu
  •   

在这个例子中,如果我把
 程序代码
*+html #zishu_test li a:hover span {margin-left:-8px; }/* IE7*/ 
这行删除;那么在IE7中;就会有差别了;

为了解决这个问题,我看了;http://www.blueidea.com/tech/site/2006/3626.asp 里边的一种方法; 但是如果程序员和布局人不是同一个人的话;这样的方法很不好控制; 于是才有了下边的方法;

以下是代码; 
 程序代码
复制代码 代码如下:
* html #zishu_test li a:hover span {margin-left:-8px; } /* IE6 */  
*+html #zishu_test li a:hover span {margin-left:-8px; }/* IE7*/  

这是针对IE6和IE7的两种方法;
“*+html”被ie7与ie5.01所使用,而区分ie7与ie5.01又有很简单的方法,便是important,把important写在前面,这样才能形成了单独针对ie7 hack的方法了。

比如:

*+html div.IE7 { 
width:200px; !important; 
width:100px;
}

以上就是当ie7不认!important之后 [布局的解决办法]的详细内容,更多请关注本站其它相关文章!

《当ie7不认!important之后 [布局的解决办法].doc》

下载本文的Word格式文档,以方便收藏与打印。