ie6,ie7,ff 的css兼容hack写法

时间:2022-04-23
本文章向大家介绍ie6,ie7,ff 的css兼容hack写法,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type='text/css'>
#example { background: #ff0000;width:100px;height:100px } /* Moz/FF/IE8 beta2 */
*html #example { background: #00ff00; } /* IE6 */
*+html #example { background: #0000ff; } /* IE7 */

.demo { background: #ff0000;width:100px;height:50px } /* Moz/FF/IE8 beta2 */
*html .demo { background: #00ff00; } /* IE6 */
*+html .demo { background: #0000ff; } /* IE7 */
</style>
</head>
<title>css hack</title>
<body>
<div id="example">id示例</div>
<br />
<div class="demo">class示例</div>
</body>
</html>

在ie6下,二个div的背景为绿色,ie7下显示为蓝色,ff下显示为红色(ie8 beta2下显示跟ff相同)