CSS Hack代碼與瀏覽相容總結

來源:互聯網
上載者:User

標籤:blog   http   io   ar   color   os   sp   on   div   

關於CSS Hack的東西能少盡量少吧。發現這篇文章我寫得太複雜了,所以重新精簡了一下,把代碼粘貼到jsfiddle上,方面修改代碼和維護。

1, IE條件注釋法,微軟官方推薦的hack方式。
只在IE下生效<!--[if IE]>這段文字只在IE瀏覽器上顯示<![endif]-->只在IE6下生效<!--[if IE 6]>這段文字只在IE6瀏覽器上顯示<![endif]-->只在IE6以上版本生效<!--[if gt IE 6]>這段文字只在IE6以上版本IE瀏覽器上顯示<![endif]-->只在IE7上不生效<!--[if ! IE 7]>這段文字在非IE7瀏覽器上顯示<![endif]-->非IE瀏覽器生效<!--[if !IE]><!-->這段文字只在非IE瀏覽器上顯示<!--<![endif]-->

2.綜合一下常用的CSS Hack代碼 

Edit in JSFiddle
  • CSS
 CSS 
.csshack{    background:blue;    background:blue\9; /*all ie*/ background:blue\0/; /*ie8-ie9*/ background/*\**/: blue\9; /* ie7-ie8*/ *background:blue;/* or #background: blue */ /*ie6-ie7*/ +background:blue; /*ie7*/ _background:blue; /*ie6*/}:root .csshack{ background:blue; /*大於等於ie9*/}/* IE9, IE10 */@media screen and (min-width:0\0) { .csshack { color: red}}/* IE 10+ */@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { #veintiun { color: red; }}/* saf3+, chrome1+ */@media screen and (-webkit-min-device-pixel-ratio:0) { #diez { color: red }}/* iPhone / mobile webkit */@media screen and (max-device-width: 480px) { #veintiseis { color: red }}/* Firefox only. 1+ */#veinticuatro, x:-moz-any-link { color: red }/* Firefox 3.0+ */#veinticinco, x:-moz-any-link, x:default { color: red }/* FF 3.5+ */body:not(:-moz-handler-blocked) #cuarenta { color: red; }

3.IE CSS Media,來自這裡 3.IE CSS Media,來自這裡

/* @media hacks *//* IE6/7 only (via Keith Clarke) */@media screen\9 { }/* IE6/7/8 (via Keith Clarke) */@media \0screen\,screen\9 {}/* IE8 (via Keith Clarke) */@media \0screen { }/* IE8/9/10 */@media screen\0 { }/* IE9/10 */@media screen and (min-width:0\0) { body { background: yellow; }} 
4.button重設css樣式相容ie6,ie7

button在IE6、IE7下的相容性,需要儲值css為overflow:visible

5.讓IE6支援max-width,min-width
.sector{max-width:500px; _width:expression((documentElement.clientWidth>500)?"500px":"auto");min-width:300px; _width:expression((documentElement.clientWidth<300)?"300px":"auto");}
6.IE6下某些情況line-height無效

當在一個容器裡文字和img、input、textarea、select、object等元素相連的時候,對這個容器設定的line-height數值會失效; 同時以上元素的行高可能×2。
受影響的瀏覽器: Microsoft Internet Explorer 5.01 / Windows Microsoft Internet Explorer 5.5 / Windows Microsoft Internet Explorer 6

解決辦法:
對和文字相串連的img、input、textarea、select、object等元素加以屬性:
{margin: (所屬line-height-自身img,input,select,object高度)/2px 0;vertical-align:middle;}

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.