当前位置:编程学习 > html/css >>

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

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

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

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

<!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>zishu.cn test</title>
<style>
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;}
</style>
</head>
<body>
<div id="zishu_test">
<ul>
<li><a href=> <li><a href=> <li><a href=> <li><a href=> <li><a href=> <li><a href=> <li><a href=> </ul>
</div>
</body>
</html>

在这个例子中,如果我把
程序代码
*+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;
}

上一个:如何正确使用标题元素、段落和强制换行
下一个:IE浮动边界BUG延伸探讨

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,