CSS Hack 技巧

來源:互聯網
上載者:User

標籤:ima   gic   src   www   alt   ack   UI   分享   lib   

IE Hack

IE系列瀏覽器的hack大略如下:

  • _nowamagic:1px;———–ie6
  • *nowamagic:1px;———–ie7
  • nowamagic:1px\0;———-ie89
  • nowamagic:1px\9\0;——–ie9
  • :root nowamagic:1px;    —-ie9(實際情況可能ie9還是有問題,再用這種方式)
  • 其中粉紅色部分為屬性hack,黃色部分為選取器hack,它們可以結合使用。
Firefox 與 Chrome 的 Hack

Firefox:

@-moz-document url-prefix()    /*寫在選取器外層時(只可寫在此處):Firefox only*/

Chrome:

@media screen and (-webkit-min-device-pixel-ratio:0)    /*寫在選取器外層時(只可寫在此處):Chrome only*/

使用樣本:
@-moz-document url-prefix()    /*Firefox*/{    body    {        background-color:pink;    }}
瀏覽器對css的解析是從前到後的,並且採用最後一個樣式聲明。

CSS執行個體:
.color{    background-color: #CC00FF;         /*所有瀏覽器都會顯示為紫色*/    background-color: #FF0000\9;       /*IE6、IE7、IE8會顯示紅色*/    *background-color: #0066FF;        /*IE6、IE7會變為藍色*/                _background-color: #009933;        /*IE6會變為綠色*/}
background: red;            /* 對FF Opera和Safari有效 */#background: blue;          /* 對 IE6 和 IE7有效 */_background: green;         /* 只對IE6有效 *//*/background: orange;*/    /** 只對IE8有效 **/!important                  /*FF、IE7有效*/*                           /*IE都有效*/

IE8是可以和IE7相容的,簡單一行代碼,讓IE8自動調用IE7的渲染模式。只需要在頁面中加入如下HTTP meta-tag:<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />,只要IE8讀到這個標籤,它就會自動啟動IE7相容模式,保證頁面完整展示。

混用起來大約是這樣:
:root .demo {background:#963\9; /* 僅IE9適用 */}.demo {width: 300px;height: 200px;background: #036; /* 所有瀏覽器都適用 */background: #09F\9; /* IE6~IE9 */background: #09F\0; /* IE8~IE9 */background: #09F\0/; /* IE8 */*background: #F60; /* IE6/IE7 */+background: #F60; /* IE6/IE7 */@background: #F60; /* IE6/IE7 */>background: #F60; /* IE6/IE7 */_background: #ccc; /* IE6 */}@media all and (min-width:0) {.demo {background: #F06; /* webkit and opera */}}@media screen and (-webkit-min-device-pixel-ratio:0){.demo {background:#609;}/*webkit (& Opera9.2)*/}

原文地址:nowamagic.net


CSS Hack 技巧

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.