CSS瀏覽器安全色解決總結

來源:互聯網
上載者:User

  1. CSS中幾種瀏覽器對不同關鍵字的支援,可進行瀏覽器安全色性重複定義 !important 可被FireFox和IE7識別 * 可被IE6、IE7識別 _ 可被IE6識別 *+ 可被IE7識別

      區別IE6與FF: background:orange;*background:blue;

    區別IE6與IE7: background:green !important;background:blue;

    區別IE7與FF: background:orange; *background:green;

    區別FF,IE7,IE6: background:orange;*background:green !important;*background:blue;

     IE7,IE8相容: <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

      最新相容方案如下:
      .e{
         color:#FFF;/* FF,OP */
         [;color:#0F0;]/* Sa,CH */
         color:#FFF\9;/*IE6、7、8*/
         *color:#FF0;/* IE7、6 */
         _color:#F00;/* IE6 */
        }

  2. 應用條件注釋,因為IE各版本的瀏覽器對我們製作的WEB標準的頁面解釋不一樣,具體就是對CSS的解釋不同,我們為了相容這些,可運用條件注釋來各自訂,最終達到相容的目的。
      
      比如:

      <!– 預設先調用css.css樣式表 –>

      <link rel="stylesheet" type="text/css" href="css.css" />

      <!–[if IE 7]>

      <!– 如果IE瀏覽器版是7,調用ie7.css樣式表 –>

      <link rel="stylesheet" type="text/css" href="ie7.css" />

      <![endif]–>

      <!–[if lte IE 6]>

      <!– 如果IE瀏覽器版本小於等於6,調用ie.css樣式表 –>

      <link rel="stylesheet" type="text/css" href="ie.css" />

      <![endif]–>

     這其中就區分了IE7和IE6向下的瀏覽器對CSS的執行,達到相容的目的。同時,首行預設的css.css還能與其他非IE瀏覽器實現相容。

     注意:預設的CSS樣式應該位於HTML文檔的首行,進行條件注釋判斷的所有內容必須位於該預設樣式之後。
   
  3. 幾個瀏覽器對實際像素的解釋 IE/Opera:對象的實際寬度 = (margin-left) + width + (margin-right) Firefox/Mozilla:對象的實際寬度= (margin-left) + (border-left-width) + (padding- left) + width + (padding-right) + (border-right-width) + (margin-right)

  4. 滑鼠手勢問題:FireFox的cursor屬性不支援hand,但是支援pointer,IE兩個都支援;所以為了相容都用pointer

  5. FireFox中設定HTML標籤的Style屬性時,所有位置、寬高和尺寸值必須後跟px,IE也支援此寫法,因此統一加px單位。如 Obj.Style.Height = imgObj.Style.Height + ‘px';

  6. FireFox無法解析簡寫的padding屬性設定,如padding 5px 4px 3px 1px;必須改為 padding-top:5px; padding-right:4px; padding-bottom:3px; padding-left:1px0;

  7. 消除ul、ol等列表的縮排時,樣式應寫成:list-style:none;margin:0px;padding:0px;其中margin屬性對IE有效,padding屬性對FireFox有效

  8. CSS控制透明:IE:filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60); FireFox:opacity:0.6;

  9. CSS控制圓角:IE:不支援圓角; FireFox: -moz-border-radius:4px;或 -moz-border-radius-topleft:4px; -moz-border-radius-topright:4px; -moz-border-radius-bottomleft:4px; -moz-border-radius- bottomright:4px;

  10. CSS雙線凹凸邊框:IE:border:2px outset; FireFox: -moz-border-top-colors: #d4d0c8 white; -moz-border-left-colors: #d4d0c8 white; -moz-border-right-colors:#404040 #808080; -moz-border-bottom-colors:#404040 #808080;

  11. IE支援CSS方法cursor:url()自訂游標樣式檔案和捲軸顏色風格;FireFox對以上兩者均不支援

  12. IE有Select控制項永遠處於最上層的bug,且所有CSS對Select控制項都不起作用

  13. IE支援Form中的Label標籤,包括圖片和文字內容;FireFox不支援包含圖片的Label,點擊圖片不能讓標記 label for 的Radio或CheckBox產生效果

  14. FireFox中的TextArea不支援onScroll事件

  15. FireFox不支援display的inline和block

  16. FireFox對Div設定margin-left, margin-right為auto時已經置中, IE中不行

  17. FireFox對Body設定text-align時, Div需要設定margin: auto(主要是margin-left margin-right) 方可置中

  18. 對超連結的CSS樣式設定最好遵從這樣的順序:L-V-H-A。即 <style type="text/css"> <!-- a:link {} a:visited {} a:hover {} a:active {} --> </style> 這樣可以避免一些訪問過後的超連結就不具備hover和active樣式了

  19. IE中設定長段落自動換行在CSS中設定word-wrap:break-word;FireFox中使用JS插入 的方法來實現,具體代碼如下: <script type="text/javascript"> /* <![CDATA[ */ function toBreakWord(el, intLen){ var obj=document.getElementById(el); var strContent=obj.innerHTML; var strTemp=""; while(strContent.length>intLen){ strTemp+=strContent.substr(0,intLen)+" "; strContent=strContent.substr(intLen,strContent.length); } strTemp+=" "+strContent; obj.innerHTML=strTemp; } if(document.getElementById && !document.all) toBreakWord("div_id", 37); /* ]]> */ </script>

  20. 在子容器加了浮動屬性後,該容器將不能自動撐開解決方案:在標籤結束後下一個標籤中加上一個清除浮動的CSS clear:both;

  21. 浮動後IE6解釋外邊距為實際邊距的雙倍 解決辦法:加上display:inline

  22. IE6片下方會有空隙 解決辦法:為img加上display:block或設定vertical-align 屬性為vertical-align:top | bottom |middle |text-bottom

  23. IE6下兩個層中間有空隙 解決辦法:設定右側div也同樣浮動float:left或者相對IE6定義 margin-right:-3px;

  24. LI中內容超過長度後以省略符號的顯示方法 <style type="text/css"> <!-- li { width:200px; white-space:nowrap; text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden; } --> </style> (只適用與IE)

  25. 將元素的高度和行高設定成相同值,即可垂直置中文本 <style type="text/css"> <!-- div { height:30px; line-height:30px; } --> </style>

  26. 對齊文本與文本輸入框,須在CSS中增加vertical-align:middle;屬性設定 <style type="text/css"> <!-- … … vertical-align:middle; } --> </style>

  27. 支援WEB標準的瀏覽器設定了固定高度值就不會像IE6那樣被撐開,但是又想設定固定高度又想能夠被撐開呢?解決辦法是去掉height屬性而設定min-height,為了相容不支援min-height的IE6可以這樣定義: { height:auto!important; height:200px; min-height:200px; }

  28. web標準中IE無法設定捲軸顏色 解決辦法:在CSS中對body的設定改為對html的 <style type="text/css"> <!-- html { scrollbar-face-color:#f6f6f6; scrollbar-highlight-color:#fff; scrollbar-shadow-color:#eeeeee; scrollbar-3dlight-color:#eeeeee; scrollbar-arrow-color:#000; scrollbar-track-color:#fff; scrollbar-darkshadow-color:#fff; } --> </style>

  29. IE6由於預設行高問題無法定義1px左右高度的容器,解決辦法:在CSS中對容器設定如:overflow:hidden | zoom:0.08 | line-height:1px

  30. 給Flash設定透明屬性可使層顯示在Flash之上 <param name="wmode" value="transparent" /> <!-- 解決IE上的問題 //> <embed wmode="transparent" …… > <!-- 解決FireFox上的問題 //>

  31. FireFox設定Padding屬性後會相應的增加Width和Height屬性值,IE不會解決辦法:用!important方法多定義一套Height和Width

  32. FireFox對div與div之間的空格是忽略的,但IE是處理的;因此盡量在兩個相連的div之間不要有空格和斷行符號,否則可能會造成不同瀏覽器之間格式不正確,比如著名的3px偏差;而且原因很難查明

  33. 形如如下格式 <div id="parent"> <div id="content"> </div> </div> 當Content內容多時,即使parent設定了高度100%或auto,在不同瀏覽器下還是不能完好的自動伸展;解決辦法在層的最下方產生一個高度為1的空格,代碼如下 <div id="parent"> <div id="content"> </div> <div style="font: 0px/0px sans-serif;clear: both;display: block"> </div> </div>

  34. IE和FireFox對字型small的尺寸解釋不同,FireFox為13px,IE中為16px

  35. IE和FireFox對空格的尺寸解釋不同,FireFox為4px,IE中為8px

 

相關文章

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.