秋風的蕭瑟 又見湖邊木葉飛

          歡迎來到梁良 | LonBlog,這里記錄下了我生活點點滴滴。

          web標準常見問題大全 讓FireFox與IE兼容

           web標準常見問題大全 讓FireFox與IE兼容
          1.超鏈接訪問過后hover樣式就不出現(xiàn)的問題
          被點擊訪問過的超鏈接樣式不在具有hover和active了,很多人應該都遇到過這個問題,解決方法是改變CSS屬性的排列順序: L-V-H-A
          Code: 

          1. <style type="text/css">   
          2. <!--    
          3. a:link {}   
          4. a:visited {}   
          5. a:hover {}   
          6. a:active {}   
          7. -->   
          8. </style>  
          Java代碼
          1. <style type="text/css">  
          2. <!--   
          3. a:link {}  
          4. a:visited {}  
          5. a:hover {}  
          6. a:active {}  
          7. -->  
          8. </style>  


          2.FireFox下如何使連續(xù)長字段自動換行
          眾所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我們使用JS插入的方法來解決
          Code: 

          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>  
          Java代碼
          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>  

          Js代碼
          1. <scrīpt type="text/javascrīpt">   
          2. /* <![CDATA[ */  
          3. function toBreakWord(el, intLen){   
          4.     var ōbj=document.getElementById(el);   
          5.     var strContent=obj.innerHTML;     
          6.     var strTemp="";   
          7.     while(strContent.length>intLen){   
          8.         strTemp+=strContent.substr(0,intLen)+"   
          9. ";     
          10.         strContent=strContent.substr(intLen,strContent.length);     
          11.     }   
          12.     strTemp+="   
          13. "+strContent;   
          14.     obj.innerHTML=strTemp;   
          15. }   
          16. if(document.getElementById  &&  !document.all)  toBreakWord("ff"37);   
          17. /* ]]> */  
          18. </script>  
          Java代碼
          1. <scrīpt type="text/javascrīpt">  
          2. /* <![CDATA[ */  
          3. function toBreakWord(el, intLen){  
          4.     var ōbj=document.getElementById(el);  
          5.     var strContent=obj.innerHTML;    
          6.     var strTemp="";  
          7.     while(strContent.length>intLen){  
          8.         strTemp+=strContent.substr(0,intLen)+"  
          9. ";    
          10.         strContent=strContent.substr(intLen,strContent.length);    
          11.     }  
          12.     strTemp+="  
          13. "+strContent;  
          14.     obj.innerHTML=strTemp;  
          15. }  
          16. if(document.getElementById  &&  !document.all)  toBreakWord("ff"37);  
          17. /* ]]> */  
          18. </script>  


          3.ff下為什么父容器的高度不能自適應
          在子容器加了浮動屬性后,該容器將不能自動撐開,解決方法是在標簽結束后加上一個清除浮動的元素。
          Code: 

          1. clear: both;  
          Java代碼
          1. clear: both;  


          4.IE6 的雙倍邊距BUG
          浮動后本來外邊距10px,但IE解釋為20px,解決辦法是加上
          Code: 

          1. display: inline  
          Java代碼
          1. display: inline  


          5. IE6下絕對定位的容器內(nèi)文本無法正常選擇的問題
          此問題在IE6、7中存在,解決問題的辦法是讓IE進入到qurks mode。關于qurks mode的相關知識,請參考:
          [url]http://www.microsoft.com/china/msdn/library/webservices/asp.net/
          ASPNETusStan.mspx?mfr=true[/url]

          6. IE6下為什么圖片下方有空隙產(chǎn)生
          解決這個BUG的方法也有很多,可以是改變html的排版,或者設置img 為display:block 或者設置vertical-align 屬性為vertical-align:top | bottom |middle |text-bottom
          都可以解決.

          7. IE6下兩個層中間怎么有間隙
          這個IE的3PX BUG也是經(jīng)常出現(xiàn)的,解決的辦法是給.right也同樣浮動 float:left 或者相對IE6定義.left margin-right:-3px;

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

          9. LI中內(nèi)容超過長度后以省略號顯示的方法
          此方法適用與IE與OP瀏覽器
          Code: 

          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>  
          Java代碼
          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>  


          10.web標準中定義id與class有什么區(qū)別嗎
          一.web標準中是不容許重復ID的,比如 div id="aa" 不容許重復2次,而class 定義的是類,理論上可以無限重復, 這樣需要多次引用的定義便可以使用他.
          二.屬性的優(yōu)先級問題
          ID 的優(yōu)先級要高于class,看上面的例子
          三.方便JS等客戶端腳本,如果在頁面中要對某個對象進行腳本操作,那么可以給他定義一個ID,否則只能利用 遍歷頁面元素加上指定特定屬性來找到它,這是相對浪費時間資源,遠遠不如一個ID來得簡單.

          11.如何垂直居中文本
          將元素高度和行高設為一致。
          Code: 

          1. <style type="text/css">   
          2. <!--    
          3. div {   
          4.     height:30px;   
          5.     line-height:30px;   
          6.     border:1px solid red   
          7.     }   
          8. -->   
          9. </style>  
          Java代碼
          1. <style type="text/css">  
          2. <!--   
          3. div {  
          4.     height:30px;  
          5.     line-height:30px;  
          6.     border:1px solid red  
          7.     }  
          8. -->  
          9. </style>  


          12.如何對齊文本與文本輸入框
          加上 vertical-align:middle;
          Code: 

          1. <style type="text/css">   
          2. <!--    
          3. input {   
          4.     width:200px;   
          5.     height:30px;   
          6.     border:1px solid red;   
          7.     vertical-align:middle;   
          8. }    
          9. -->   
          10. </style>  
          Java代碼
          1. <style type="text/css">  
          2. <!--   
          3. input {  
          4.     width:200px;  
          5.     height:30px;  
          6.     border:1px solid red;  
          7.     vertical-align:middle;  
          8. }   
          9. -->  
          10. </style>  


          13.為什么FF下面不能水平居中呢
          FF下面設置容器的左右外補丁為auto就可以了
          Code: 

          1. <style type="text/css">   
          2. <!--    
          3. div {   
          4.     margin:0 auto;   
          5. }   
          6. -->   
          7. </style>  
          Java代碼
          1. <style type="text/css">  
          2. <!--   
          3. div {  
          4.     margin:0 auto;  
          5. }  
          6. -->  
          7. </style>  


          14.為什么FF下文本無法撐開容器的高度
          標準瀏覽器中固定高度值的容器是不會象IE6里那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設置呢?辦法就是去掉height設置 min-height:200px; 這里為了照顧不認識min-height的IE6 可以這樣定義:
          Code: 

          1. {   
          2. height:auto!important;   
          3. height:200px;   
          4. min-height:200px;   
          5. }  
          Java代碼
          1. {  
          2. height:auto!important;  
          3. height:200px;  
          4. min-height:200px;  
          5. }  


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

          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 標準常見問題大全</div>  
          Java代碼
          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標準常見問題大 全</div>  


          問 題的差別在于容器的整體寬度有沒有將邊框(border)的寬度算在其內(nèi),這里IE6解釋為200PX ,而FF則解釋為220PX,那究竟是怎么導致的問題呢?大家把容器頂部的xml去掉就會發(fā)現(xiàn)原來問題出在這,頂部的申明觸發(fā)了IE的qurks mode,關于qurks mode、standards mode的相關知識,請參考:
          [url]http://www.microsoft.com/china/msdn/library/webservices/asp.net/
          ASPNETusStan.mspx?mfr=true[/url]

          16.為什么web標準中IE無法設置滾動條顏色了
          解決辦法是將body換成html
          Code: 

          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>  
          Java代碼
          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>  


          17.為什么我定義的樣式?jīng)]有作用呢
          這里你無法用.aa定義到li 遇到這種情況怎么解決呢?答案是提高.aa 的優(yōu)先權 比如#aa ul li.aa
          Code: 

          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標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web 標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題 大全web標準常見問題大全web標準常見問題大全web標準常見問題大全   
          17. </li>   
          18. </ul>   
          19. </div>  
          Java代碼
          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 標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題 大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標 準常見問題大全  
          17. </li>  
          18. </ul>  
          19. </div>  


          18.為什么無法定義1px左右高度的容器
          IE6下這個問題是因為默認的行高造成的,解決的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px

          19.為什么這個背景顏色無法顯示

          Code: 

          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 標準常見問題大全</li>   
          21. <li>web標準常見問題大 全</li>   
          22. <li>web標準常見問題大全</li>   
          23. <li>web 標準常見問題大全</li>   
          24. <li>web標準常見問題大 全</li>   
          25. <div style="clear:both"></div>   
          26. </ul>  
          Java代碼
          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 標準常見問題大全</li>  
          21. <li>web標準常見問題大 全</li>  
          22. <li>web標準常見問題大全</li>  
          23. <li>web 標準常見問題大全</li>  
          24. <li>web標準常見問題大 全</li>  
          25. <div style="clear:both"></div>  
          26. </ul>  

          IE中設置有背景色的ul并沒有顯示出來,這個屬于haslayout問題,解決的辦法也很多參考 http://www.satzansatz.de/cssd/onhavinglayout.htm
          解決方法之一:
          Code: 

          1. <!--[if lte IE 6]>   
          2. <style>   
          3. .gainlayout { height: 1px; }   
          4. </style>   
          5. <![endif]-->    
          Java代碼
          1. <!--[if lte IE 6]>  
          2. <style>  
          3. .gainlayout { height: 1px; }  
          4. </style>  
          5. <![endif]-->    


          20.怎么樣才能讓層顯示在FLASH之上呢
          解決的辦法是給FLASH設置透明
          Code:
          <param name="wmode" value="transparent" />

          21.怎樣使一個層垂直居中于瀏覽器中
          這里我們使用百分比絕對定位,與外補丁負值的方法,負值的大小為其自身寬度高度除以二
          Code: 

          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>  
          Java代碼
          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>  


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

          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>  
          Java代碼
          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>  

          或者使用背景圖的辦法:
          Code:
          background:url("logo.gif") center no-repeat;

          23.如何讓div橫向排列
          橫向排列DIV可以使用浮動的方式比如float:left,或者設置對象為內(nèi)聯(lián),還可以絕對定位對象等等.
          Code: 

          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>   
          13. <div>web標準常見問題大全</div>   
          14. <div>web 標準常見問題大全</div>   
          15. <div>web標準常見問題大 全</div>

          posted on 2010-04-11 00:17 梁良 閱讀(335) 評論(0)  編輯  收藏 所屬分類: CSS

          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導航

          公告

              歡迎光臨

          常用鏈接

          隨筆分類

          隨筆檔案

          相冊

          .我的網(wǎng)站.

          友情博客

          開源社區(qū)

          科技博客

          資料網(wǎng)站

          最新隨筆

          搜索

          最新評論

          閱讀排行榜

          Powered by:
          LonLeung
          Copyright © 梁良

          本頁生成時間:毫秒

          主站蜘蛛池模板: 济阳县| 沿河| 舞钢市| 阜康市| 济源市| 奎屯市| 隆昌县| 措勤县| 阿合奇县| 濉溪县| 四会市| 无棣县| 越西县| 甘孜县| 巴东县| 芦山县| 青川县| 百色市| 上高县| 阜平县| 平南县| 临城县| 山西省| 蓬安县| 客服| 赣州市| 丁青县| 曲沃县| 吉安市| 郴州市| 昌都县| 根河市| 丽水市| 灵山县| 江津市| 合山市| 华容县| 荆门市| 东至县| 桦南县| 巍山|