CSS HACK收集:关于IE6/FF/google等浏览器hack的方法详细

一、IE6 下
a标签嵌套img标签IE下会有边框,那是超链接默认的样式,解决办法:img{border:0 none;}
1、终极方法:条件注释
!--[if lte IE 6] 这段文字仅显示在 IE6及IE6以下版本 。![endif]--
!--[if gte IE 6] 这段文字仅显示在 IE6及IE6以上版本 。![endif]--
!--[if gt IE 6] 这段文字仅显示在 IE6以上版本(不包含IE6) 。![endif]--
!--[if IE 5.5] 这段文字仅显示在 IE5.5 。![endif]--
!--在 IE6及IE6以下版本中加载css--
!--[if lte IE 6] link type=text/css rel=stylesheet href=https://www.rkxy.com.cn/dnjc/css/ie6.css mce_href=css/ie6.css /![endif]--
缺点是在IE浏览器下可能会增加额外的HTTP请求数 。
2、CSS选择器区分
IE6不支持子选择器;先针对IE6使用常规申明CSS选择器,然后再用子选择器针对IE7 及其他浏览器 。
/* IE6 专用 */
.content {color:red;}
【CSS HACK收集:关于IE6/FF/google等浏览器hack的方法详细】/* 其他浏览器 */
divp .content {color:blue;} --
3、PNG半透明图片的问题
虽然可以通过JS等方式解决,但依然存在载入速度等问题,所以,这个在设计上能避免还是尽量避免为好 。以达到网站最大优化 。
4、IE6下的圆角
IE6不支持CSS3的圆角属性,性价比最高的解决方法就是用图片圆角来替代,或者放弃IE6的圆角 。
5、IE6背景闪烁
如果你给链接、按钮用CSS sprites作为背景,你可能会发现在IE6下会有背景图闪烁的现象 。造成这个的原因是由于IE6没有将背景图缓存,每次触发hover的时候都会重新加载,可以用JavaScript设置IE6缓存这些图片:
document.execCommand(BackgroundImageCache,false,true);
6、最小高度
IE6 不支持min-height属性,但它却认为height就是最小高度 。解决方法:使用ie6不支持但其余浏览器支持的属性!important 。
#container {min-height:200px; height:auto !important; height:200px;}
7、最大高度
//直接使用ID来改变元素的最大高度
var container = document.getElementById(’container’);
container.style.height = (container.scrollHeight199) ? 200px : auto;
//写成函数来运行
function setMaxHeight(elementId, height){
var container = document.getElementById(elementId);
container.style.height = (container.scrollHeight(height - 1)) ? heightpx : auto;
}
//函数示例
setMaxHeight(’container1’, 200);
setMaxHeight(’container2’, 500);
8、100% 高度
在IE6下,如果要给元素定义100%高度,必须要明确定义它的父级元素的高度,如果你需要给元素定义满屏的高度,就得先给html和body定义height:100%; 。
9、最小宽度
同max-height和max-width一样,IE6也不支持min-width 。
//直接使用ID来改变元素的最小宽度
var container = document.getElementById(’container’);
container.style.width = (container.clientWidthwidth) ? 500px : auto;
//写成函数来运行
function setMinWidth(elementId, width){
var container = document.getElementById(elementId);
container.style.width = (container.clientWidthwidth) ? widthpx : auto;
}
//函数示例
setMinWidth(’container1’, 200);
setMinWidth(’container2’, 500);
10、最大宽度
//直接使用ID来改变元素的最大宽度
var container = document.getElementById(elementId);
container.style.width = (container.clientWidth(width - 1)) ? widthpx : auto;
//写成函数来运行
function setMaxWidth(elementId, width){
var container = document.getElementById(elementId);
container.style.width = (container.clientWidth(width - 1)) ? widthpx : auto;
}
//函数示例
setMaxWidth(’container1’, 200);
setMaxWidth(’container2’, 500);
11、双边距Bug
当元素浮动时,IE6会错误的把浮动方向的margin值双倍计算 。个人觉得较好解决方法是避免float和margin同时使用 。

推荐阅读