---
title: "CSS兼容IE6,IE7,FIREFOX的hack收集"
author: "jarod2008"
date: "2009-05-14T17:32:03Z"
tags: ["CSS", "Firefox", "HTML", "IE", "浏览器"]
slug: "css-ie6-ie7-firefox-hack"
draft: false
lastmod: "2009-05-14T17:32:03Z"
id: 386959
url: "https://jarod2008.iteye.com/blog/386959"
---

CSS兼容IE6,IE7,FIREFOX的hack收集  
一种，是CSS HACK的方法注意顺序。  
程序代码 程序代码  
height:20px; /\*For Firefox\*/  
\*height:25px; /\*For IE7 & IE6\*/  
\_height:20px; /\*For IE6\*/

下面是针对id或者是自定义的样式也属于CSS HACK，不过没有上面这样简洁。  
程序代码 程序代码  
#example { color: #333; } /* Moz \*/  
\* html #example { color: #666; } /* IE6 \*/  
\*+html #example { color: #999; } /* IE7 \*/

第二种是使用IE专用的条件注释，也就是在引用或者导入css的时候使用“注释判断”来兼容。  
程序代码 程序代码  
&lt;!--其他浏览器 --&gt;  
&lt;link rel="stylesheet" type="text/css" href="css.css" /&gt;  
&lt;!--\[if IE 7]&gt;  
&lt;link rel="stylesheet" type="text/css" href="ie7.css" /&gt;  
&lt;!\[endif]--&gt;  
&lt;!--\[if lte IE 6]&gt;  
&lt;link rel="stylesheet" type="text/css" href="ie.css" /&gt;  
&lt;!\[endif]--&gt;