关于css hack的问题
题目要求:定义一个50*50的div在按照下面背景色显示,ie6:red,ie7:yellow,ie8:black,ie9:blue,opera:orange,chrome:green,其他:white;
解决方案如下:
1 !DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <style type="text/css"> 7 .div{ 8 width: 50px; 9 height:50px; 10 /*other*/ 11 background-color: white; 12 /*ie8*/ 13 background-color: black\0; 14 /*ie9*/ 15 background-color: blue\9\0; 16 /*ie7*/ 17 +background-color:yellow; 18 /*ie6*/ 19 _background-color:red; 20 21 } 22 /*chrome*/ 23 @media screen and (-webkit-min-device-pixel-ratio:0) { .div { background-color: green; } 24 25 /*opera*/ 26 @media all and (-webkit-min-device-pixel-ratio:10000),not and all (-webkit-min-device-pixel-ratio:0) { .div{background-color:orange;} } 27 28 </style> 29 </head> 30 <body> 31 <div class="div"></div> 32 </body> 33 </html>