自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

讓FireFox與IE兼容 CSS常見問題大全

開發(fā) 前端
在前端開發(fā)中,我們經(jīng)常遇到瀏覽器的兼容性問題,特別是IE與FireFox之間,文章列舉了常見的一些CSS兼容性問題,及相關(guān)的解決方法。

在前端開發(fā)中,我們經(jīng)常遇到瀏覽器的兼容性問題,特別是IE與FireFox之間。文章列舉了開發(fā)人員比較常見的FireFox與IE之間的兼容性問題,同時(shí)給出了相關(guān)的解決方法。

51CTO相關(guān)閱讀:CSS hack:實(shí)現(xiàn)IE6、IE7、Firefox兼容

1.超鏈接訪問過后hover樣式就不出現(xiàn)的問題

被點(diǎn)擊訪問過的超鏈接樣式不在具有hover和active了,很多人應(yīng)該都遇到過這個(gè)問題,解決方法是改變CSS屬性的排列順序: L-V-H-A:

  1. <style type="text/css">     
  2. <!--      
  3. a:link {}     
  4. a:visited {}     
  5. a:hover {}     
  6. a:active {}     
  7. -->     
  8. </style>    
  9.  
  10. <style type="text/css"> 
  11. <!--   
  12. a:link {}  
  13. a:visited {}  
  14. a:hover {}  
  15. a:active {}  
  16. --> 
  17. </style> 

2.FireFox下如何使連續(xù)長字段自動(dòng)換行

眾所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我們使用JS插入&#10;的方法來解決:

  1. <style type="text/css">     
  2. <!--      
  3. div {     
  4.     width:300px;     
  5.     word-wrap:break-word;     
  6.     border:1px solid red;     
  7. }     
  8. -->     
  9. </style>     
  10. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa     
  11. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa     
  12. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa     
  13. aaaaaaaaaaaaaaaaaaaaaaaaaaa</div>    
  14.  
  15. <style type="text/css"> 
  16. <!--   
  17. div {  
  18.     width:300px;  
  19.     word-wrap:break-word;  
  20.     border:1px solid red;  
  21. }  
  22. --> 
  23. </style> 
  24. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  25. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  26. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  27. aaaaaaaaaaaaaaaaaaaaaaaaaaa</div> 
  28. Java代碼   
  29. <scrīpt type="text/javascrīpt">     
  30. /* <![CDATA[ */    
  31. function toBreakWord(el, intLen){     
  32.     var ōbj=document.getElementById(el);     
  33.     var strContent=obj.innerHTML;       
  34.     var strTemp="";     
  35.     while(strContent.length>intLen){     
  36.         strTemp+=strContent.substr(0,intLen)+"&#10;";       
  37.         strContent=strContent.substr(intLen,strContent.length);       
  38.     }     
  39.     strTemp+="&#10;"+strContent;     
  40.     obj.innerHTML=strTemp;     
  41. }     
  42. if(document.getElementById  &&  !document.all)  toBreakWord("ff", 37);     
  43. /* ]]> */    
  44. </script>    
  45.  
  46. <scrīpt type="text/javascrīpt"> 
  47. /* <![CDATA[ */  
  48. function toBreakWord(el, intLen){  
  49.     var ōbj=document.getElementById(el);  
  50.     var strContent=obj.innerHTML;    
  51.     var strTemp="";  
  52.     while(strContent.length>intLen){  
  53.         strTemp+=strContent.substr(0,intLen)+"&#10;";    
  54.         strContent=strContent.substr(intLen,strContent.length);    
  55.     }  
  56.     strTemp+="&#10;"+strContent;  
  57.     obj.innerHTML=strTemp;  
  58. }  
  59. if(document.getElementById  &&  !document.all)  toBreakWord("ff", 37);  
  60. /* ]]> */  
  61. </script> 

3.ff下為什么父容器的高度不能自適應(yīng)

在子容器加了浮動(dòng)屬性后,該容器將不能自動(dòng)撐開,解決方法是在標(biāo)簽結(jié)束后加上一個(gè)清除浮動(dòng)的元素。

  1. clear: both;    
  2. clear: both; 

4.IE6的雙倍邊距BUG

浮動(dòng)后本來外邊距10px,但I(xiàn)E解釋為20px,解決辦法是加上:

  1. display: inline    
  2. display: inline 

5. IE6下絕對(duì)定位的容器內(nèi)文本無法正常選擇的問題

此問題在IE6、7中存在,解決問題的辦法是讓IE進(jìn)入到qurks mode。

6. IE6下為什么圖片下方有空隙產(chǎn)生

解決這個(gè)BUG的方法也有很多,可以是改變html的排版,或者設(shè)置img 為display:block 或者設(shè)置vertical-align 屬性為vertical-align:top | bottom |middle |text-bottom
都可以解決.

7. IE6下兩個(gè)層中間怎么有間隙

這個(gè)IE的3PX BUG也是經(jīng)常出現(xiàn)的,解決的辦法是給.right也同樣浮動(dòng) float:left 或者相對(duì)IE6定義.left margin-right:-3px;

8. list-style-image無法準(zhǔn)確定位的問題

list-style-image的定位問題也是經(jīng)常有人問的,解決的辦法一般是用li的背景模擬,這里采用相對(duì)定位的方法也可以解決。

9. LI中內(nèi)容超過長度后以省略號(hào)顯示的方法

此方法適用與IE與OP瀏覽器:

  1. <style type="text/css">     
  2. <! --      
  3. li {     
  4.     width: 200px;     
  5.     white-space:nowrap;     
  6.     text-overflow:ellipsis;      
  7.     -o-text-overflow:ellipsis;      
  8.     overflow: hidden;     
  9.     }     
  10. -->     
  11. </style>    
  12.  
  13. <style type="text/css"> 
  14. <! --   
  15. li {  
  16.     width: 200px;  
  17.     white-space:nowrap;  
  18.     text-overflow:ellipsis;   
  19.     -o-text-overflow:ellipsis;   
  20.     overflow: hidden;  
  21.     }  
  22. --> 
  23. </style> 

#p#

10.web標(biāo)準(zhǔn)中定義id與class有什么區(qū)別嗎

一.web標(biāo)準(zhǔn)中是不容許重復(fù)ID的。

比如 div id="aa"  不容許重復(fù)2次,而class 定義的是類,理論上可以無限重復(fù), 這樣需要多次引用的定義便可以使用他.

二.屬性的優(yōu)先級(jí)問題。

ID 的優(yōu)先級(jí)要高于class,看上面的例子。

三.方便JS等客戶端腳本。

如果在頁面中要對(duì)某個(gè)對(duì)象進(jìn)行腳本操作,那么可以給他定義一個(gè)ID,否則只能利用遍歷頁面元素加上指定特定屬性來找到它,這是相對(duì)浪費(fèi)時(shí)間資源,遠(yuǎn)遠(yuǎn)不如一個(gè)ID來得簡單.

11.如何垂直居中文本

將元素高度和行高設(shè)為一致。

  1. <style type="text/css">     
  2. <!--      
  3. div {     
  4.     height:30px;     
  5.     line-height:30px;     
  6.     border:1px solid red     
  7.     }     
  8. -->     
  9. </style>    
  10.  
  11. <style type="text/css"> 
  12. <!--   
  13. div {  
  14.     height:30px;  
  15.     line-height:30px;  
  16.     border:1px solid red  
  17.     }  
  18. --> 
  19. </style> 

 

12.如何對(duì)齊文本與文本輸入框

  1. 加上vertical-align:middle;   
  2.  
  3. <style type="text/css">     
  4. <!--      
  5. input {     
  6.     width:200px;     
  7.     height:30px;     
  8.     border:1px solid red;     
  9.     vertical-align:middle;     
  10. }      
  11. -->     
  12. </style>    
  13.  
  14. <style type="text/css"> 
  15. <!--   
  16. input {  
  17.     width:200px;  
  18.     height:30px;  
  19.     border:1px solid red;  
  20.     vertical-align:middle;  
  21. }   
  22. --> 
  23. </style> 

13.為什么FF下面不能水平居中呢

FF下面設(shè)置容器的左右外補(bǔ)丁為auto就可以了。

  1. <style type="text/css">     
  2. <!--      
  3. div {     
  4.     margin:0 auto;     
  5. }     
  6. -->     
  7. </style>    
  8.  
  9. <style type="text/css"> 
  10. <!--   
  11. div {  
  12.     margin:0 auto;  
  13. }  
  14. --> 
  15. </style> 

14.為什么FF下文本無法撐開容器的高度

標(biāo)準(zhǔn)瀏覽器中固定高度值的容器是不會(huì)象IE6里那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設(shè)置呢?辦法就是去掉height設(shè)置min-height:200px;  這里為了照顧不認(rèn)識(shí)min-height的IE6 可以這樣定義:

  1. {     
  2. height:auto!important;     
  3. height:200px;     
  4. min-height:200px;     
  5. }    
  6.  
  7. {  
  8. height:auto!important;  
  9. height:200px;  
  10. min-height:200px;  
  11. }  

15.為什么IE6下容器的寬度和FF解釋不同呢

  1. <?xml version="1.0" encoding="gb2312"?>     
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />     
  4. <style type="text/css">     
  5. <!--     
  6. div {     
  7.     cursor:pointer;     
  8.     width:200px;     
  9.     height:200px;     
  10.     border:10px solid red     
  11.     }     
  12. -->     
  13. </style>     
  14. <div ōnclick="alert(this.offsetWidth)">web標(biāo)準(zhǔn)常見問題大全</div>    
  15.  
  16. <?xml version="1.0" encoding="gb2312"?> 
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  18. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  19. <style type="text/css"> 
  20. <!--  
  21. div {  
  22.     cursor:pointer;  
  23.     width:200px;  
  24.     height:200px;  
  25.     border:10px solid red  
  26.     }  
  27. --> 
  28. </style> 
  29. <div ōnclick="alert(this.offsetWidth)">web標(biāo)準(zhǔn)常見問題大全</div> 

問題的差別在于容器的整體寬度有沒有將邊框(border)的寬度算在其內(nèi),這里IE6解釋為200PX ,而FF則解釋為220PX,那究竟是怎么導(dǎo)致的問題呢?大家把容器頂部的xml去掉就會(huì)發(fā)現(xiàn)原來問題出在這,頂部的申明觸發(fā)了IE的qurks mode。

16.為什么web標(biāo)準(zhǔn)中IE無法設(shè)置滾動(dòng)條顏色了

解決辦法是將body換成html:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     
  2. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />     
  3. <style type="text/css">     
  4. <!--      
  5. html {     
  6.     scrollbar-face-color:#f6f6f6;     
  7.     scrollbar-highlight-color:#fff;     
  8.     scrollbar-shadow-color:#eeeeee;     
  9.     scrollbar-3dlight-color:#eeeeee;     
  10.     scrollbar-arrow-color:#000;     
  11.     scrollbar-track-color:#fff;     
  12.     scrollbar-darkshadow-color:#fff;     
  13.     }     
  14. -->     
  15. </style>    
  16.  
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  18. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  19. <style type="text/css"> 
  20. <!--   
  21. html {  
  22.     scrollbar-face-color:#f6f6f6;  
  23.     scrollbar-highlight-color:#fff;  
  24.     scrollbar-shadow-color:#eeeeee;  
  25.     scrollbar-3dlight-color:#eeeeee;  
  26.     scrollbar-arrow-color:#000;  
  27.     scrollbar-track-color:#fff;  
  28.     scrollbar-darkshadow-color:#fff;  
  29.     }  
  30. --> 
  31. </style> 

#p#

17.為什么我定義的樣式?jīng)]有作用呢

這里你無法用.aa定義到li 遇到這種情況怎么解決呢?答案是提高.aa 的優(yōu)先權(quán)。

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     
  2. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />     
  3. <style type="text/css">     
  4. <!--     
  5. #aa ul li {     
  6.     color:red     
  7.     }     
  8. .aa {     
  9.     color:blue     
  10.     }     
  11. -->     
  12. </style>     
  13. <div id="aa">     
  14. <ul>     
  15. <li class="aa">     
  16. web標(biāo)準(zhǔn)常見問題大全  
  17. </li>     
  18. </ul>     
  19. </div>    
  20.  
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  22. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  23. <style type="text/css"> 
  24. <!--  
  25. #aa ul li {  
  26.     color:red  
  27.     }  
  28. .aa {  
  29.     color:blue  
  30.     }  
  31. --> 
  32. </style> 
  33. <div id="aa"> 
  34. <ul> 
  35. <li class="aa"> 
  36. web標(biāo)準(zhǔn)常見問題大全  
  37. </li> 
  38. </ul> 
  39. </div> 

18.為什么無法定義1px左右高度的容器

IE6下這個(gè)問題是因?yàn)槟J(rèn)的行高造成的,解決的方法也有很多,例如:

  1. overflow:hidden | zoom:0.08 | line-height:1px
  2.   

19.為什么這個(gè)背景顏色無法顯示

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     
  2. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />     
  3. <style type="text/css">     
  4. <!--      
  5. ul {     
  6.     background:red     
  7.     }     
  8. li {     
  9.     float:left;     
  10.     width:180px;     
  11.     }     
  12. -->     
  13. </style>     
  14. <!--[if lte IE 6]>     
  15. <style>     
  16. .gainlayout { height: 1px; }     
  17. </style>     
  18. <![endif]-->       
  19. <ul class="gainlayout">     
  20. <li>web標(biāo)準(zhǔn)常見問題大全</li>     
  21. <li>web標(biāo)準(zhǔn)常見問題大全</li>     
  22. <li>web標(biāo)準(zhǔn)常見問題大全</li>     
  23. <li>web標(biāo)準(zhǔn)常見問題大全</li>     
  24. <li>web標(biāo)準(zhǔn)常見問題大全</li>     
  25. <div style="clear:both"></div>     
  26. </ul>    
  27.  
  28. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  29. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  30. <style type="text/css"> 
  31. <!--   
  32. ul {  
  33.     background:red  
  34.     }  
  35. li {  
  36.     float:left;  
  37.     width:180px;  
  38.     }  
  39. --> 
  40. </style> 
  41. <!--[if lte IE 6]> 
  42. <style> 
  43. .gainlayout { height: 1px; }  
  44. </style> 
  45. <![endif]-->    
  46. <ul class="gainlayout"> 
  47. <li>web標(biāo)準(zhǔn)常見問題大全</li> 
  48. <li>web標(biāo)準(zhǔn)常見問題大全</li> 
  49. <li>web標(biāo)準(zhǔn)常見問題大全</li> 
  50. <li>web標(biāo)準(zhǔn)常見問題大全</li> 
  51. <li>web標(biāo)準(zhǔn)常見問題大全</li> 
  52. <div style="clear:both"></div> 
  53. </ul> 
  54.  
  55. <!--[if lte IE 6]>     
  56. <style>     
  57. .gainlayout { height: 1px; }     
  58. </style>     
  59. <![endif]-->      
  60.  
  61. <!--[if lte IE 6]> 
  62. <style> 
  63. .gainlayout { height: 1px; }  
  64. </style> 
  65. <![endif]-->   

20.怎么樣才能讓層顯示在FLASH之上呢

  1. 解決的辦法是給FLASH設(shè)置透明:  
  2. <param name="wmode" value="transparent" />
  3.   

21.怎樣使一個(gè)層垂直居中于瀏覽器中

這里我們使用百分比絕對(duì)定位,與外補(bǔ)丁負(fù)值的方法,負(fù)值的大小為其自身寬度高度除以二:

  1. <style type="text/css">     
  2. <!--      
  3. div {     
  4.     position:absolute;     
  5.     top:50%;     
  6.     left:50%;     
  7.     margin:-100px 0 0 -100px;     
  8.     width:200px;     
  9.     height:200px;     
  10.     border:1px solid red;     
  11.     }     
  12. -->     
  13. </style>    
  14.  
  15. <style type="text/css"> 
  16. <!--   
  17. div {  
  18.     position:absolute;  
  19.     top:50%;  
  20.     left:50%;  
  21.     margin:-100px 0 0 -100px;  
  22.     width:200px;  
  23.     height:200px;  
  24.     border:1px solid red;  
  25.     }  
  26. --> 
  27. </style> 

22 .圖片垂直與容器內(nèi)

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     
  2. <style type="text/css">     
  3. <!--      
  4. * {margin:0;padding:0}     
  5. div {     
  6.     width:500px;     
  7.     height:500px;     
  8.     border:1px solid #ccc;     
  9.     overflow:hidden;     
  10.     position:relative;     
  11.     display:table-cell;     
  12.     text-align:center;     
  13.     vertical-align:middle     
  14.     }     
  15. div p {     
  16.     position:static;     
  17.     +position:absolute;     
  18.     top:50%     
  19.     }     
  20. img {     
  21.     position:static;     
  22.     +position:relative;     
  23.     top:-50%;left:-50%;     
  24.     width:276px;     
  25.     height:110px     
  26.     }     
  27. -->     
  28. </style>     
  29. <div><p><img src="logo.gif" /></p></div>    
  30.  
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  32. <style type="text/css"> 
  33. <!--   
  34. * {margin:0;padding:0}  
  35. div {  
  36.     width:500px;  
  37.     height:500px;  
  38.     border:1px solid #ccc;  
  39.     overflow:hidden;  
  40.     position:relative;  
  41.     display:table-cell;  
  42.     text-align:center;  
  43.     vertical-align:middle  
  44.     }  
  45. div p {  
  46.     position:static;  
  47.     +position:absolute;  
  48.     top:50%  
  49.     }  
  50. img {  
  51.     position:static;  
  52.     +position:relative;  
  53.     top:-50%;left:-50%;  
  54.     width:276px;  
  55.     height:110px  
  56.     }  
  57. --> 
  58. </style> 
  59. <div><p><img src="logo.gif" /></p></div> 

或者使用背景圖的辦法:

  1. background:url("logo.gif") center no-repeat; 
  2.  

23.如何讓div橫向排列

橫向排列DIV可以使用浮動(dòng)的方式比如float:left,或者設(shè)置對(duì)象為內(nèi)聯(lián),還可以絕對(duì)定位對(duì)象等等。

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     
  2. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />     
  3. <style type="text/css">     
  4. <!--      
  5. div {     
  6.     float:left;     
  7.     width:200px;     
  8.     height:200px;     
  9.     border:1px solid red     
  10.     }     
  11. -->     
  12. </style>  

 

【編輯推薦】

  1. CSS規(guī)范:你真的了解盒模型嗎?
  2. DIV+CSS中常見十大錯(cuò)誤總結(jié)
  3. CSS hack:實(shí)現(xiàn)IE6、IE7、Firefox兼容 
責(zé)任編輯:王曉東 來源: javaeye博客
相關(guān)推薦

2010-09-01 14:51:12

CSSIEFirefox

2010-09-01 15:16:47

CSSIEFirefox

2010-08-19 17:06:16

IEFirefox

2010-08-31 09:24:29

FireFoxIECSS

2010-08-27 15:08:10

FirefoxIE6IE7

2010-09-15 11:26:05

IE火狐CSS兼容性

2010-09-06 15:06:29

IE6IE7Firefox

2010-08-19 16:06:15

2010-08-18 15:02:54

IEFirefox兼容

2010-08-18 15:22:28

IE6IE7Firefox

2010-09-16 13:17:31

IE6IE7IE8

2010-09-15 09:21:11

IEirefoxJavascript

2010-08-27 15:38:21

兼容IE6IE7

2010-08-30 09:35:35

IE6IE7Firefox

2010-08-18 15:57:14

IE6IE7IE8

2010-09-16 13:33:47

IE6IE7IE8

2010-01-06 16:23:45

Linux常見問題

2010-08-27 15:56:52

IEFirefoxCSS

2010-08-23 09:23:48

IEFirefox兼容性

2010-08-20 14:47:02

IEFirefoxCSS
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)