列舉了一些常見,新手經常問的問題。舉例並說明解決方法。(內容在下面對應) 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樣式就不出現的問題
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- a:link {
- color:red
- }
- a:hover {
- color:blue
- }
- a:visited {
- color:green
- }
- a:active {
- color:orange
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <a href="#">
- web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
- </a>
- </body>
- </html>
複製代碼
被點擊訪問過的超鏈接樣式不在具有hover和active了,很多人應該都遇到過這個問題,解決方法是改變CSS屬性的排列順序: L-V-H-A
2.FF下如何使連續長字段自動換行
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- width:300px;
- word-wrap:break-word;
- border:1px solid red;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
- <script type="text/javascript">
- // <![CDATA[
- function toBreakWord(intLen){
- var obj=document.getElementById("ff");
- 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(37)
- // ]]>
- </script>
- </body>
- </html>
複製代碼
衆所周知IE中直接使用 word-wrap:break-word 就可以了, 這裏FF中我們使用JS插入 的方法來解決
3.ff下爲什麼父容器的高度不能自適應
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- width:200px;
- border:1px solid red
- }
- p {
- float:left;
- width:100px;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <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>
- </body>
- </html>
複製代碼
爲什麼這個P撐不開DIV呢?解決的辦法是在div 與 p 之間插入<div style="clear:both"></div>清除掉這個p的浮動. 什麼?你在IE下也碰到過類似問題!那麼參考:http://bbs.blueidea.com/viewthread.php?tid=2636904
4. IE6的雙倍邊距BUG
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- body {
- margin:0
- }
- div {
- float:left;
- margin-left:10px;
- width:200px;
- height:200px;
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>
- <a href="#">
- web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
- </a>
- </div>
- </body>
- </html>
複製代碼
浮動後本來外邊距10px,但IE解釋爲20px,解決辦法是加上display:inline
5. IE6下絕對定位的容器內文本無法正常選擇的問題
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- position:absolute;
- top:100px;
- left:100px;
- width:200px;
- height:200px;
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>
- <a href="#">
- web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
- </a>
- </div>
- </body>
- </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下爲什麼圖片下方有空隙產生
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- border:1px solid red;
- background:orange;
- }
- img {
- width:276px;
- height:110px;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>
- <img src="http://www.google.com/intl/en_ALL/images/logo.gif" alt="google" />
- </div>
- </body>
- </html>
複製代碼
解決這個BUG的方法也有很多,可以是改變html的排版,或者定義img 爲display:block 或者定義vertical-align屬性值爲vertical-align:top | bottom |middle |text-bottom 還可以設置父容器的字體大小爲零,font-size:0
7. IE6下這兩個層中間怎麼有間隙
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- .left {
- float:left;
- width:100px;
- height:100px;
- background:red
- }
- .right {
- width:100px;
- height:100px;
- background:orange;
- overflow:hidden;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div class="left">aaaaaa</div>
- <div class="right">aaaaaa</div>
- </body>
- </html>
複製代碼
這個IE的3PX BUG也是經常出現的,解決的辦法是給.right也同樣浮動 float:left 或者相對IE6定義.left margin-right:-3px;
8. list-style-image無法準確定位的問題
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- li {
- list-style:url("http://bbs.blueidea.com/attachments/2006/11/10/arrowb_kJrcZheJmiIF.gif");
- }
- li a {
- position:relative;
- top:-5px;
- font:12px/25px 宋體;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <ul>
- <li><a href="#">web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全</a></li>
- </ul>
- </body>
- </html>
複製代碼
這個list-style-image的定位問題也是經常有人問的,解決的辦法一般是用li的背景模擬,這裏採用相對定位的方法也可以解決
9. LI中內容超過長度後以省略號顯示的方法
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- li {
- width:200px;
- white-space:nowrap;
- text-overflow:ellipsis;
- -o-text-overflow:ellipsis;
- overflow: hidden;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <ul>
- <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
- <li><a href="#">web標準常見問題大全web標準常見問題大全</a></li>
- </body>
- </html>
複製代碼
此方法適用與IE與OP瀏覽器
10.web標準中定義id與class有什麼區別嗎
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- #aa {
- color:red
- }
- .aa {
- color:blue
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div id="aa" class="aa">
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- </div>
- </body>
- </html>
複製代碼
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- .a {
- color:orange
- }
- .b {
- background:#eee
- }
- .c {
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div class="a b c">aaaaaaaa</div>
- </body>
- </html>
複製代碼
一. web標準中是不容許重複ID的,比如 div id="aa" 一個頁面中不容許重複2次,而class 定義的是類,理論上可以無限重複的, 這樣需要多次引用的定義便可以使用他.class還可以同時引用多個類,不同的類之間用空格隔開. 二. 屬性的優先級問題,ID 的優先級要高於class,看上面的例子 三. 方便JS等客戶端腳本,如果在頁面中要對某個對象進行腳本操作,那麼可以給他定義一個ID,否則只能利用遍歷頁面元素加上指定特定屬性來找到它,這是相對浪費時間資源,遠遠不如一個ID來得簡單.
11.如何垂直居中文本
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- height:30px;
- line-height:30px;
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>web標準常見問題大全</div>
- </body>
- </html>
複製代碼
給容器設置一個與其高度相同的行高就可以了
12.如何對齊文本與文本輸入筐
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- input {
- width:200px;
- height:30px;
- border:1px solid red;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <input type="text" />aaaaaaaaaaaaaaaaaa
- </body>
- </html>
複製代碼
遇到此種問題,設置文本框的 vertical-align:middle 就可以了
13.爲什麼FF下面不能水平居中呢
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- body {
- text-align:center;
- }
- div {
- margin:0 auto;
- width:500px;
- height:200px;
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div></div>
- </body>
- </html>
複製代碼
FF下面設置容器的左右外補丁爲auto就可以了
14.爲什麼FF下文本無法撐開容器的高度
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- width:200px;
- height:200px;
- border:1px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <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>
- </body>
- </html>
複製代碼
標準瀏覽器中固定高度值的容器是不會象IE6裏那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設置呢?辦法就是去掉height設置min-height:200px; 這裏爲了照顧不認識min-height的IE6 可以這樣定義: { height:auto!important; height:200px; min-height:200px; }
15.爲什麼IE6下容器的寬度和FF解釋不同呢
- <?xml version="1.0" encoding="gb2312"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- cursor:pointer;
- width:200px;
- height:200px;
- border:10px solid red
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div οnclick="alert(this.offsetWidth)">web標準常見問題大全</div>
- <hr/>
- </body>
- </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無法設置滾動條顏色了
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- body {
- 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>
- </head>
- <body>
- <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/>
- </body>
- </html>
複製代碼
解決辦法是將body換成html
17.爲什麼我定義的樣式沒有作用呢
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- #aa ul li {
- color:red
- }
- .aa {
- color:blue
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div id="aa">
- <ul>
- <li class="aa">
- web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
- </li>
- </ul>
- </div>
- </body>
- </html>
複製代碼
這裏你無法用.aa定義到li 遇到這種情況怎麼解決呢?答案是提高.aa 的優先權 比如#aa ul li.aa 優先權相關文章參考-baidu搜索關鍵詞: CSS的優先權
18.爲什麼無法定義1px左右高度的容器
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- background:red;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div> </div>
- </body>
- </html>
複製代碼
IE6下這個問題是因爲默認的行高造成的,解決的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px
19.爲什麼這個背景顏色無法顯示
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- ul {
- background:red
- }
- li {
- float:left;
- width:180px;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <ul>
- <li>web標準常見問題大全</li>
- <li>web標準常見問題大全</li>
- <li>web標準常見問題大全</li>
- <li>web標準常見問題大全</li>
- <li>web標準常見問題大全</li>
- <div style="clear:both"></div>
- </ul>
- </body>
- </html>
複製代碼
IE中設置有背景色的ul並沒有顯示出來,這個屬於haslayout問題,解決的辦法也很多參考:http://bbs.blueidea.com/viewthread.php?tid=2636904
20.怎麼樣才能讓層顯示在FLASH之上呢
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- position:absolute;
- top:20px;
- left:20px;
- width:200px;
- height:200px;
- background:red
- }
- object {
- width:500px;
- height:100px;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>
- web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
- </div>
- <object type="application/x-shockwave-flash" data="http://gg.blueidea.com/2005/www/m533-104.swf">
- <param name="movie" value="http://gg.blueidea.com/2005/www/m533-104.swf" />
- </object>
- </body>
- </html>
複製代碼
解決的辦法是給FLASH設置透明<param name="wmode" value="transparent" />或者<param name="wmode" value="opaque" />
21.怎樣使一個層垂直居中於瀏覽器中
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- position:absolute;
- top:50%;
- left:50%;
- margin:-100px 0 0 -100px;
- width:200px;
- height:200px;
- border:1px solid red;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div>web標準常見問題大全</div>
- </body>
- </html>
複製代碼
這裏我們使用百分比絕對定位,與外補丁負值的方法,負值的大小爲其自身寬度高度除以二
22 .圖片垂直於容器內
參考:http://bbs.blueidea.com/thread-2666987-1-1.html
23.如何讓三列橫向排列
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- float:left;
- margin:1px;
- width:200px;
- height:200px;
- background:orange
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div></div>
- <div></div>
- <div></div>
- </body>
- </html>
複製代碼
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- position:absolute;
- top:50%;
- left:50%;
- margin:-100px 0 0 -300px;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div style="background:#404040;width:200px;height:200px;">1</div>
- <div style="background:#FD7C03;width:200px;height:200px;margin:-100px 0 0 -100px;">2</div>
- <div style="background:#eee;width:200px;height:200px;margin:-100px 0 0 100px;">3</div>
- </body>
- </html>
複製代碼
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- span {
- margin:1px;
- display:-moz-inline-box;
- display:inline-block;
- width:300px;
- height:200px;
- background:orange;
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <span></span>
- <span></span>
- <span></span>
- </body>
- </html>
複製代碼
橫向排列DIV可以使用浮動的方式比如float:left,或者用內聯方式,還可以絕對定位對象等等
24.通用的加入收藏夾代碼
- <script type="text/javascript">
- // <![CDATA[
- function bookmark(){
- var title=document.title
- var url=document.location.href
- if (window.sidebar) window.sidebar.addPanel(title, url,"");
- else if( window.opera && window.print ){
- var mbm = document.createElement('a');
- mbm.setAttribute('rel','sidebar');
- mbm.setAttribute('href',url);
- mbm.setAttribute('title',title);
- mbm.click();}
- else if( document.all ) window.external.AddFavorite( url, title);
- }
- // ]]>
- </script>
- <a href="javascript:bookmark()">加入收藏夾</a>
複製代碼
經常有朋友說他的加入收藏夾代碼只支持IE,上面的例子可以很好的解決這個問題,在IE6-7. FF2.0 OP9.0中測試通過
25.複製到系統剪貼板之IE,ff兼容版
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <script type="text/javascript">
- // <![CDATA[
- function copy_clip(copy){
- if (window.clipboardData){
- window.clipboardData.setData("Text", copy);}
- else if (window.netscape){
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
- if (!clip) return;
- var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
- if (!trans) return;
- trans.addDataFlavor('text/unicode');
- var str = new Object();
- var len = new Object();
- var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
- var copytext=copy;
- str.data=copytext;
- trans.setTransferData("text/unicode",str,copytext.length*2);
- var clipid=Components.interfaces.nsIClipboard;
- if (!clip) return false;
- clip.setData(trans,null,clipid.kGlobalClipboard);}
- alert("已複製"+copy)
- return false;
- }
- // ]]>
- </script>
- <h1>請另存代碼測試</h1>
- <input type="text" id="ff" value="www.blueidea.com" /><button οnclick="copy_clip(document.getElementById('ff').value)">複製
- </button>
複製代碼
26.javascript爲FF設置首頁
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <script type="text/javascript">
- // <![CDATA[
- function setHomePage(){
- if(window.netscape){
- try {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- }
- catch (e) {}}
- var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
- prefs.setCharPref('browser.startup.homepage','http://www.blueidea.com');
- }
- // ]]>
- </script>
- <a href="#" οnclick="setHomePage()">設置首頁</a>
複製代碼
27.IE6使用濾鏡使PNG圖片透明後,容器內鏈接失效的問題。
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- div {
- width:401px;
- height:223px;
- filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='http://bbs.blueidea.com/attachments/2006/9/11/bg_nT9Vi2i45To0.png')
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <div><a href="#">27.IE6使用濾鏡使PNG圖片透明後,容器內鏈接失效的問題。</a></div>
- </body>
- </html>
複製代碼
解決方法是爲鏈接定義一個相對定位屬性。position:relative
28.禁用文本框中文輸入法的通用方法。
- <div>驗證碼<input type="text" style="ime-mode:disabled"/></div>
複製代碼
IE可以用ime-mode:disabled,firefox3也開始支持IE的這一私有屬性
對於其他不支持的瀏覽器可以用如下方法模擬
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
- <head profile="http://www.w3.org/2000/08/w3c-synd/#">
- <meta http-equiv="content-language" content="zh-cn" />
- <meta http-equiv="content-type" content="text/html;charset=gb2312" />
- <title>blueidea</title>
- <style type="text/css">
- /*<![CDATA[*/
- input,textarea {
- width:300px;
- height:20px;
- border:1px solid
- }
- textarea {
- height:150px
- }
- #pw {
- opacity:0;
- display:block;
- position:relative;
- margin-top:-24px
- }
- #tt,#pw {
- width:100px
- }
- /*]]>*/
- </style>
- </head>
- <body>
- <table>
- <tr>
- <td>標題</td>
- <td><input type="text"/></td>
- </tr>
- <tr>
- <td>內容</td>
- <td><textarea></textarea></td>
- </tr>
- <tr>
- <td>驗證碼</td>
- <td><input type="text" id="tt"/><input type="password" id="pw"/></td>
- </tr>
- </table>
- <script type="text/javascript">
- // <![CDATA[
- var ee = document.getElementById('pw');
- ee.onkeyup = function p() {
- document.getElementById('tt').value = ee.value;
- }
- // ]]>
- </script>
- </body>
- </html>
複製代碼
|