`
webcode
  • 浏览: 5955961 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

Portal项目中的Hack

 
阅读更多
hack :是解决页面浏览器不兼容的技巧方法。

IE和Firefox的display兼容性问题解决

正确兼容IE和Firefox的写法应该是这样的:

document.getElementById("test").style.display="block";//IE
document.getElementById("test").style.display="table-row";//FF

完整写法是:
document.getElementById("test").style.display=document.all?"block":"table-row";

另外还有个注意的问题【兼容IE和Firefox的写法】:

document.getElementById("test").style.display="";//显示

document.getElementById("test").style.display="none";//隐藏

HTML兼容性

所有浏览器 通用
height: 100px;
IE6 专用
_height: 100px;
IE6 专用
*height: 100px;
IE7 专用
*+height: 100px;
IE7、FF 共用
height: 100px !important;

CSS 兼容

以下两种方法几乎能解决现今所有兼容.
1, !important (不是很推荐,用下面的一种感觉最安全)
随着IE7对!important的支持, !important 方法现在只针对IE6的兼容.(注意写法.记得该声明位置需要提前.)
代码:
<style>
#wrapper {
width: 100px!important; /* IE7+FF */
width: 80px; /* IE6 */
}
</style>
2, IE6/IE77对FireFox <from 针对firefox ie6 ie7的css样式>
*+html 与 *html 是IE特有的标签, firefox 暂不支持.而*+html 又为 IE7特有标签.
代码:
<style>
#wrapper { width: 120px; } /* FireFox */
*html #wrapper { width: 80px;} /* ie6 fixed */
*+html #wrapper { width: 60px;} /* ie7 fixed, 注意顺序 */
</style>
注意:
*+html 对IE7的兼容 必须保证HTML顶部有如下声明:
代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics