web標準常見問題整理

 

web標準常見問題整理

列舉了一些常見,新手經常問的問題。舉例並說明解決方法。(內容在下面對應)
1.超鏈接訪問過後hover樣式就不出現的問題
2.FF下如何使連續長字段自動換行
3.ff下爲什麼父容器的高度不能自適應
4. IE6的雙倍邊距BUG
5. IE6下絕對定位的容器內文本無法正常選擇的問題
6. IE6下爲什麼圖片下方有空隙產生
7. IE6下這兩個層中間怎麼有間隙
8. list-style-image無法準確定位的問題
9. LI中內容超過長度後以省略號顯示的方法
10.web標準中定義id與class有什麼區別嗎
11.如何垂直居中文本
12.如何對齊文本與文本輸入筐
13.爲什麼FF下面不能水平居中呢
14.爲什麼FF下文本無法撐開容器的高度
15.爲什麼IE6下容器的寬度和FF解釋不同呢
16.爲什麼web標準中IE無法設置滾動條顏色了
17.爲什麼我定義的樣式沒有作用呢
18.爲什麼無法定義1px左右高度的容器
19.爲什麼這個背景顏色無法顯示
20.怎麼樣才能讓層顯示在FLASH之上呢
21.怎樣使一個層垂直居中於瀏覽器中
22 .圖片垂直與容器內
23.如何讓三列橫向排列
24.通用的加入收藏夾代碼
25.複製到系統剪貼板之IE,ff兼容版
26.javascript爲FF設置首頁
27.IE6使用濾鏡使PNG圖片透明後,容器內鏈接失效的問題
28.禁用文本框中文輸入法的通用方法

1.超鏈接訪問過後hover樣式就不出現的問題
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. a:link {
  10. color:red
  11. }
  12. a:hover {
  13. color:blue
  14. }
  15. a:visited {
  16. color:green
  17. }
  18. a:active {
  19. color:orange
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <a href="#">
  26. web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
  27. </a>
  28. </body>
  29. </html>
複製代碼
被點擊訪問過的超鏈接樣式不在具有hover和active了,很多人應該都遇到過這個問題,解決方法是改變CSS屬性的排列順序: L-V-H-A

2.FF下如何使連續長字段自動換行
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:300px;
  11. word-wrap:break-word;
  12. border:1px solid red;
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
  19. <script type="text/javascript">
  20. // <![CDATA[
  21. function toBreakWord(intLen){
  22. var obj=document.getElementById("ff");
  23. var strContent=obj.innerHTML;
  24. var strTemp="";
  25. while(strContent.length>intLen){
  26. strTemp+=strContent.substr(0,intLen)+" ";
  27. strContent=strContent.substr(intLen,strContent.length);
  28. }
  29. strTemp+=" "+strContent;
  30. obj.innerHTML=strTemp;
  31. }
  32. if(document.getElementById && !document.all) toBreakWord(37)
  33. // ]]>
  34. </script>
  35. </body>
  36. </html>
複製代碼
衆所周知IE中直接使用    word-wrap:break-word 就可以了, 這裏FF中我們使用JS插入&#10;的方法來解決


3.ff下爲什麼父容器的高度不能自適應
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:200px;
  11. border:1px solid red
  12. }
  13. p {
  14. float:left;
  15. width:100px;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <div><p>web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全</p></div>
  22. </body>
  23. </html>
複製代碼
爲什麼這個P撐不開DIV呢?解決的辦法是在div 與 p 之間插入<div style="clear:both"></div>清除掉這個p的浮動.
什麼?你在IE下也碰到過類似問題!那麼參考:http://bbs.blueidea.com/viewthread.php?tid=2636904



4. IE6的雙倍邊距BUG
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. margin:0
  11. }
  12. div {
  13. float:left;
  14. margin-left:10px;
  15. width:200px;
  16. height:200px;
  17. border:1px solid red
  18. }
  19. /*]]>*/
  20. </style>
  21. </head>
  22. <body>
  23. <div>
  24. <a href="#">
  25. web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
  26. </a>
  27. </div>
  28. </body>
  29. </html>
複製代碼
浮動後本來外邊距10px,但IE解釋爲20px,解決辦法是加上display:inline

5. IE6下絕對定位的容器內文本無法正常選擇的問題
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:100px;
  12. left:100px;
  13. width:200px;
  14. height:200px;
  15. border:1px solid red
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <a href="#">
  23. web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
  24. </a>
  25. </div>
  26. </body>
  27. </html>
複製代碼
上面的問題在IE6、7中存在,解決問題的辦法是讓IE進入到quirks mode。關於quirks mode的相關知識,請參考:http://www.microsoft.com/china/m ... sStan.mspx?mfr=true
aoao:在IE6版本是6.0.2900.2180.xpsp_sp2.gdr.070227-2254好像依然存在問題,加了背景色依然無效。接着測試中。。。



6. IE6下爲什麼圖片下方有空隙產生
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. border:1px solid red;
  11. background:orange;
  12. }
  13. img {
  14. width:276px;
  15. height:110px;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <img src="http://www.google.com/intl/en_ALL/images/logo.gif" alt="google" />
  23. </div>
  24. </body>
  25. </html>
複製代碼
解決這個BUG的方法也有很多,可以是改變html的排版,或者定義img 爲display:block
或者定義vertical-align屬性值爲vertical-align:top | bottom |middle |text-bottom
還可以設置父容器的字體大小爲零,font-size:0



7. IE6下這兩個層中間怎麼有間隙
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. .left {
  10. float:left;
  11. width:100px;
  12. height:100px;
  13. background:red
  14. }
  15. .right {
  16. width:100px;
  17. height:100px;
  18. background:orange;
  19. overflow:hidden;
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <div class="left">aaaaaa</div>
  26. <div class="right">aaaaaa</div>
  27. </body>
  28. </html>
複製代碼
這個IE的3PX BUG也是經常出現的,解決的辦法是給.right也同樣浮動 float:left 或者相對IE6定義.left margin-right:-3px;


8. list-style-image無法準確定位的問題
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. li {
  10. list-style:url("http://bbs.blueidea.com/attachments/2006/11/10/arrowb_kJrcZheJmiIF.gif");
  11. }
  12. li a {
  13. position:relative;
  14. top:-5px;
  15. font:12px/25px 宋體;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <ul>
  22. <li><a href="#">web標準常見問題大全</a></li>
  23. <li><a href="#">web標準常見問題大全</a></li>
  24. <li><a href="#">web標準常見問題大全</a></li>
  25. <li><a href="#">web標準常見問題大全</a></li>
  26. <li><a href="#">web標準常見問題大全</a></li>
  27. </ul>
  28. </body>
  29. </html>
複製代碼
這個list-style-image的定位問題也是經常有人問的,解決的辦法一般是用li的背景模擬,這裏採用相對定位的方法也可以解決

9. LI中內容超過長度後以省略號顯示的方法


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. li {
  10. width:200px;
  11. white-space:nowrap;
  12. text-overflow:ellipsis;
  13. -o-text-overflow:ellipsis;
  14. overflow: hidden;
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <ul>
  21. <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
  22. <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
  23. <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
  24. <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
  25. <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
  26. </body>
  27. </html>
複製代碼



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


10.web標準中定義id與class有什麼區別嗎


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. #aa {
  10. color:red
  11. }
  12. .aa {
  13. color:blue
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div id="aa" class="aa">
  20. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  21. </div>
  22. </body>
  23. </html>
複製代碼


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. .a {
  10. color:orange
  11. }
  12. .b {
  13. background:#eee
  14. }
  15. .c {
  16. border:1px solid red
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div class="a b c">aaaaaaaa</div>
  23. </body>
  24. </html>
複製代碼


一.
web標準中是不容許重複ID的,比如 div id="aa" 一個頁面中不容許重複2次,而class 定義的是類,理論上可以無限重複的, 這樣需要多次引用的定義便可以使用他.class還可以同時引用多個類,不同的類之間用空格隔開.
二.
屬性的優先級問題,ID 的優先級要高於class,看上面的例子
三.
方便JS等客戶端腳本,如果在頁面中要對某個對象進行腳本操作,那麼可以給他定義一個ID,否則只能利用遍歷頁面元素加上指定特定屬性來找到它,這是相對浪費時間資源,遠遠不如一個ID來得簡單.



11.如何垂直居中文本


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. height:30px;
  11. line-height:30px;
  12. border:1px solid red
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div>web標準常見問題大全</div>
  19. </body>
  20. </html>
複製代碼



給容器設置一個與其高度相同的行高就可以了


12.如何對齊文本與文本輸入筐


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. input {
  10. width:200px;
  11. height:30px;
  12. border:1px solid red;
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <input type="text" />aaaaaaaaaaaaaaaaaa
  19. </body>
  20. </html>
複製代碼



遇到此種問題,設置文本框的    vertical-align:middle 就可以了


13.爲什麼FF下面不能水平居中呢


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. text-align:center;
  11. }
  12. div {
  13. margin:0 auto;
  14. width:500px;
  15. height:200px;
  16. border:1px solid red
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div></div>
  23. </body>
  24. </html>
複製代碼



FF下面設置容器的左右外補丁爲auto就可以了


14.爲什麼FF下文本無法撐開容器的高度
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:200px;
  11. height:200px;
  12. border:1px solid red
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div>web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見</div>
  19. </body>
  20. </html>
複製代碼
標準瀏覽器中固定高度值的容器是不會象IE6裏那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設置呢?辦法就是去掉height設置min-height:200px;  這裏爲了照顧不認識min-height的IE6 可以這樣定義:
{
height:auto!important;
height:200px;
min-height:200px;
}



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. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  4. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  5. <meta http-equiv="content-language" content="zh-cn" />
  6. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  7. <title>blueidea</title>
  8. <style type="text/css">
  9. /*<![CDATA[*/
  10. div {
  11. cursor:pointer;
  12. width:200px;
  13. height:200px;
  14. border:10px solid red
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <div οnclick="alert(this.offsetWidth)">web標準常見問題大全</div>
  21. <hr/>
  22. </body>
  23. </html>
複製代碼
問題的差別在於容器的整體寬度有沒有將邊框(border)的寬度算在其內,這裏IE6解釋爲200PX ,而FF則解釋爲220PX,那究竟是怎麼導致的問題呢?大家把容器頂部的xml去掉就會發現原來問題出在這,頂部的申明觸發了IE的quirks mode,關於quirks mode、standards mode的相關知識,請參考:http://www.microsoft.com/china/msdn/library/webservices/asp.net/ASPNETusStan.mspx?mfr=true


16.爲什麼web標準中IE無法設置滾動條顏色了
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. scrollbar-face-color:#f6f6f6;
  11. scrollbar-highlight-color:#fff;
  12. scrollbar-shadow-color:#eeeeee;
  13. scrollbar-3dlight-color:#eeeeee;
  14. scrollbar-arrow-color:#000;
  15. scrollbar-track-color:#fff;
  16. scrollbar-darkshadow-color:#fff;
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
  23. </body>
  24. </html>
複製代碼
解決辦法是將body換成html


17.爲什麼我定義的樣式沒有作用呢
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. #aa ul li {
  10. color:red
  11. }
  12. .aa {
  13. color:blue
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div id="aa">
  20. <ul>
  21. <li class="aa">
  22. web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
  23. </li>
  24. </ul>
  25. </div>
  26. </body>
  27. </html>
複製代碼
這裏你無法用.aa定義到li 遇到這種情況怎麼解決呢?答案是提高.aa 的優先權 比如#aa ul li.aa 優先權相關文章參考-baidu搜索關鍵詞: CSS的優先權


18.爲什麼無法定義1px左右高度的容器
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. background:red;
  11. }
  12. /*]]>*/
  13. </style>
  14. </head>
  15. <body>
  16. <div> </div>
  17. </body>
  18. </html>
複製代碼
IE6下這個問題是因爲默認的行高造成的,解決的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px

19.爲什麼這個背景顏色無法顯示

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. ul {
  10. background:red
  11. }
  12. li {
  13. float:left;
  14. width:180px;
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <ul>
  21. <li>web標準常見問題大全</li>
  22. <li>web標準常見問題大全</li>
  23. <li>web標準常見問題大全</li>
  24. <li>web標準常見問題大全</li>
  25. <li>web標準常見問題大全</li>
  26. <div style="clear:both"></div>
  27. </ul>
  28. </body>
  29. </html>
複製代碼


IE中設置有背景色的ul並沒有顯示出來,這個屬於haslayout問題,解決的辦法也很多參考:http://bbs.blueidea.com/viewthread.php?tid=2636904

20.怎麼樣才能讓層顯示在FLASH之上呢
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:20px;
  12. left:20px;
  13. width:200px;
  14. height:200px;
  15. background:red
  16. }
  17. object {
  18. width:500px;
  19. height:100px;
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <div>
  26. web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
  27. </div>
  28. <object type="application/x-shockwave-flash" data="http://gg.blueidea.com/2005/www/m533-104.swf">
  29. <param name="movie" value="http://gg.blueidea.com/2005/www/m533-104.swf" />
  30. </object>
  31. </body>
  32. </html>
複製代碼


解決的辦法是給FLASH設置透明<param name="wmode" value="transparent" />或者<param name="wmode" value="opaque" />


21.怎樣使一個層垂直居中於瀏覽器中


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:50%;
  12. left:50%;
  13. margin:-100px 0 0 -100px;
  14. width:200px;
  15. height:200px;
  16. border:1px solid red;
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div>web標準常見問題大全</div>
  23. </body>
  24. </html>
複製代碼
這裏我們使用百分比絕對定位,與外補丁負值的方法,負值的大小爲其自身寬度高度除以二


22 .圖片垂直於容器內

參考:http://bbs.blueidea.com/thread-2666987-1-1.html


23.如何讓三列橫向排列
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. float:left;
  11. margin:1px;
  12. width:200px;
  13. height:200px;
  14. background:orange
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <div></div>
  21. <div></div>
  22. <div></div>
  23. </body>
  24. </html>
複製代碼
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:50%;
  12. left:50%;
  13. margin:-100px 0 0 -300px;
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div style="background:#404040;width:200px;height:200px;">1</div>
  20. <div style="background:#FD7C03;width:200px;height:200px;margin:-100px 0 0 -100px;">2</div>
  21. <div style="background:#eee;width:200px;height:200px;margin:-100px 0 0 100px;">3</div>
  22. </body>
  23. </html>
複製代碼
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. span {
  10. margin:1px;
  11. display:-moz-inline-box;
  12. display:inline-block;
  13. width:300px;
  14. height:200px;
  15. background:orange;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <span></span>
  22. <span></span>
  23. <span></span>
  24. </body>
  25. </html>
複製代碼
橫向排列DIV可以使用浮動的方式比如float:left,或者用內聯方式,還可以絕對定位對象等等



24.通用的加入收藏夾代碼
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. function bookmark(){
  4. var title=document.title
  5. var url=document.location.href
  6. if (window.sidebar) window.sidebar.addPanel(title, url,"");
  7. else if( window.opera && window.print ){
  8. var mbm = document.createElement('a');
  9. mbm.setAttribute('rel','sidebar');
  10. mbm.setAttribute('href',url);
  11. mbm.setAttribute('title',title);
  12. mbm.click();}
  13. else if( document.all ) window.external.AddFavorite( url, title);
  14. }
  15. // ]]>
  16. </script>
  17. <a href="javascript:bookmark()">加入收藏夾</a>
複製代碼
經常有朋友說他的加入收藏夾代碼只支持IE,上面的例子可以很好的解決這個問題,在IE6-7. FF2.0  OP9.0中測試通過


25.複製到系統剪貼板之IE,ff兼容版
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <script type="text/javascript">
  3. // <![CDATA[
  4. function copy_clip(copy){
  5. if (window.clipboardData){
  6. window.clipboardData.setData("Text", copy);}
  7. else if (window.netscape){
  8. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  9. var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  10. if (!clip) return;
  11. var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  12. if (!trans) return;
  13. trans.addDataFlavor('text/unicode');
  14. var str = new Object();
  15. var len = new Object();
  16. var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  17. var copytext=copy;
  18. str.data=copytext;
  19. trans.setTransferData("text/unicode",str,copytext.length*2);
  20. var clipid=Components.interfaces.nsIClipboard;
  21. if (!clip) return false;
  22. clip.setData(trans,null,clipid.kGlobalClipboard);}
  23. alert("已複製"+copy)
  24. return false;
  25. }
  26. // ]]>
  27. </script>
  28. <h1>請另存代碼測試</h1>
  29. <input type="text" id="ff" value="www.blueidea.com" /><button οnclick="copy_clip(document.getElementById('ff').value)">複製
  30. </button>
複製代碼
26.javascript爲FF設置首頁
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <script type="text/javascript">
  3. // <![CDATA[
  4. function setHomePage(){
  5. if(window.netscape){
  6. try {
  7. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  8. }
  9. catch (e) {}}
  10. var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  11. prefs.setCharPref('browser.startup.homepage','http://www.blueidea.com');
  12. }
  13. // ]]>
  14. </script>
  15. <a href="#" οnclick="setHomePage()">設置首頁</a>
複製代碼
27.IE6使用濾鏡使PNG圖片透明後,容器內鏈接失效的問題。
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:401px;
  11. height:223px;
  12. filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='http://bbs.blueidea.com/attachments/2006/9/11/bg_nT9Vi2i45To0.png')
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div><a href="#">27.IE6使用濾鏡使PNG圖片透明後,容器內鏈接失效的問題。</a></div>
  19. </body>
  20. </html>
複製代碼
解決方法是爲鏈接定義一個相對定位屬性。position:relative


28.禁用文本框中文輸入法的通用方法。
  1. <div>驗證碼<input type="text" style="ime-mode:disabled"/></div>
複製代碼

IE可以用ime-mode:disabled,firefox3也開始支持IE的這一私有屬性


對於其他不支持的瀏覽器可以用如下方法模擬
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. input,textarea {
  10. width:300px;
  11. height:20px;
  12. border:1px solid
  13. }
  14. textarea {
  15. height:150px
  16. }
  17. #pw {
  18. opacity:0;
  19. display:block;
  20. position:relative;
  21. margin-top:-24px
  22. }
  23. #tt,#pw {
  24. width:100px
  25. }
  26. /*]]>*/
  27. </style>
  28. </head>
  29. <body>
  30. <table>
  31. <tr>
  32. <td>標題</td>
  33. <td><input type="text"/></td>
  34. </tr>
  35. <tr>
  36. <td>內容</td>
  37. <td><textarea></textarea></td>
  38. </tr>
  39. <tr>
  40. <td>驗證碼</td>
  41. <td><input type="text" id="tt"/><input type="password" id="pw"/></td>
  42. </tr>
  43. </table>
  44. <script type="text/javascript">
  45. // <![CDATA[
  46. var ee = document.getElementById('pw');
  47. ee.onkeyup = function p() {
  48. document.getElementById('tt').value = ee.value;
  49. }
  50. // ]]>
  51. </script>
  52. </body>
  53. </html>
複製代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章