ie6,ie7,ff的css相容hack寫法

楊俊明發表於2009-01-11

 

img_1c53668bcee393edac0d7b3b3daff1ae.gifimg_405b18b4b6584ae338e0f6ecaf736533.gifCode
<!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相同)


相關文章