IE/Firefox中css兼容常见问题
生活随笔
收集整理的這篇文章主要介紹了
IE/Firefox中css兼容常见问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
web標準常見問題大全 讓FireFox與IE兼容
1.超鏈接訪問過后hover樣式就不出現的問題
被點擊訪問過的超鏈接樣式不在具有hover和active了,很多人應該都遇到過這個問題,解決方法是改變CSS屬性的排列順序: L-V-H-A
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? a:link?{} ?? a:visited?{} ?? a:hover?{} ?? a:active?{} ?? --> ?? </style>?? <style type="text/css">
<!--
a:link {}
a:visited {}
a:hover {}
a:active {}
-->
</style>
2.FireFox下如何使連續長字段自動換行
眾所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我們使用JS插入 的方法來解決
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? div?{ ?? ????width:300px; ?? ????word-wrap:break-word; ?? ????border:1px?solid?red; ?? } ?? --> ?? </style> ?? <div?id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?? aaaaaaaaaaaaaaaaaaaaaaaaaaa</div>?? <style type="text/css">
<!--
div {width:300px;word-wrap:break-word;border:1px solid red;
}
-->
</style>
<div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
Java代碼<scrīpt?type="text/javascrīpt"> ?? /*?<![CDATA[?*/?? function?toBreakWord(el,?intLen){ ?? ????var?ōbj=document.getElementById(el); ?? ????var?strContent=obj.innerHTML;?? ?? ????var?strTemp=""; ?? ????while(strContent.length>intLen){ ?? ????????strTemp+=strContent.substr(0,intLen)+" ";?? ?? ????????strContent=strContent.substr(intLen,strContent.length);?? ?? ????} ?? ????strTemp+=" "+strContent; ?? ????obj.innerHTML=strTemp; ?? } ?? if(document.getElementById??&&??!document.all)??toBreakWord("ff",?37); ?? /*?]]>?*/?? </script>?? <scrīpt type="text/javascrīpt">
/* <![CDATA[ */
function toBreakWord(el, intLen){var ōbj=document.getElementById(el);var strContent=obj.innerHTML; var strTemp="";while(strContent.length>intLen){strTemp+=strContent.substr(0,intLen)+" "; strContent=strContent.substr(intLen,strContent.length); }strTemp+=" "+strContent;obj.innerHTML=strTemp;
}
if(document.getElementById && !document.all) toBreakWord("ff", 37);
/* ]]> */
</script>
3.ff下為什么父容器的高度不能自適應
在子容器加了浮動屬性后,該容器將不能自動撐開,解決方法是在標簽結束后加上一個清除浮動的元素。
Code:
Java代碼clear:?both;?? clear: both;
4.IE6的雙倍邊距BUG
浮動后本來外邊距10px,但IE解釋為20px,解決辦法是加上
Code:
Java代碼display:?inline?? display: inline
5. IE6下絕對定位的容器內文本無法正常選擇的問題
此問題在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下為什么圖片下方有空隙產生
解決這個BUG的方法也有很多,可以是改變html的排版,或者設置img 為display:block 或者設置vertical-align 屬性為vertical-align:top | bottom |middle |text-bottom
都可以解決.
7. IE6下兩個層中間怎么有間隙
這個IE的3PX BUG也是經常出現的,解決的辦法是給.right也同樣浮動 float:left 或者相對IE6定義.left margin-right:-3px;
8. list-style-image無法準確定位的問題
list-style-image的定位問題也是經常有人問的,解決的辦法一般是用li的背景模擬,這里采用相對定位的方法也可以解決。
9. LI中內容超過長度后以省略號顯示的方法
此方法適用與IE與OP瀏覽器
Code:
Java代碼<style?type="text/css"> ?? <!?--? ?? li?{ ?? ????width:?200px; ?? ????white-space:nowrap; ?? ????text-overflow:ellipsis;? ?? ????-o-text-overflow:ellipsis;? ?? ????overflow:?hidden; ?? ????} ?? --> ?? </style>?? <style type="text/css">
<! --
li {width: 200px;white-space:nowrap;text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden;}
-->
</style>
10.web標準中定義id與class有什么區別嗎
一.web標準中是不容許重復ID的,比如 div id="aa"? 不容許重復2次,而class 定義的是類,理論上可以無限重復, 這樣需要多次引用的定義便可以使用他.
二.屬性的優先級問題
ID 的優先級要高于class,看上面的例子
三.方便JS等客戶端腳本,如果在頁面中要對某個對象進行腳本操作,那么可以給他定義一個ID,否則只能利用遍歷頁面元素加上指定特定屬性來找到它,這是相對浪費時間資源,遠遠不如一個ID來得簡單.
11.如何垂直居中文本
將元素高度和行高設為一致。
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? div?{ ?? ????height:30px; ?? ????line-height:30px; ?? ????border:1px?solid?red ?? ????} ?? --> ?? </style>?? <style type="text/css">
<!--
div {height:30px;line-height:30px;border:1px solid red}
-->
</style>
12.如何對齊文本與文本輸入框
加上 vertical-align:middle;
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? input?{ ?? ????width:200px; ?? ????height:30px; ?? ????border:1px?solid?red; ?? ????vertical-align:middle; ?? }? ?? --> ?? </style>?? <style type="text/css">
<!--
input {width:200px;height:30px;border:1px solid red;vertical-align:middle;
}
-->
</style>
13.為什么FF下面不能水平居中呢
FF下面設置容器的左右外補丁為auto就可以了
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? div?{ ?? ????margin:0?auto; ?? } ?? --> ?? </style>?? <style type="text/css">
<!--
div {margin:0 auto;
}
-->
</style>
14.為什么FF下文本無法撐開容器的高度
標準瀏覽器中固定高度值的容器是不會象IE6里那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設置呢?辦法就是去掉height設置min-height:200px;? 這里為了照顧不認識min-height的IE6 可以這樣定義:
Code:
Java代碼{ ?? height:auto!important; ?? height:200px; ?? min-height:200px; ?? }?? {
height:auto!important;
height:200px;
min-height:200px;
}
15.為什么IE6下容器的寬度和FF解釋不同呢
Code:
Java代碼<?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"> ?? <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/> ?? <style?type="text/css"> ?? <!-- ?? div?{ ?? ????cursor:pointer; ?? ????width:200px; ?? ????height:200px; ?? ????border:10px?solid?red ?? ????} ?? --> ?? </style> ?? <div?ōnclick="alert(this.offsetWidth)">web標準常見問題大全</div>?? <?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">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
div {cursor:pointer;width:200px;height:200px;border:10px solid red}
-->
</style>
<div ōnclick="alert(this.offsetWidth)">web標準常見問題大全</div>
問題的差別在于容器的整體寬度有沒有將邊框(border)的寬度算在其內,這里IE6解釋為200PX ,而FF則解釋為220PX,那究竟是怎么導致的問題呢?大家把容器頂部的xml去掉就會發現原來問題出在這,頂部的申明觸發了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:
Java代碼<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ?? <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/> ?? <style?type="text/css"> ?? <!--? ?? html?{ ?? ????scrollbar-face-color:#f6f6f6; ?? ????scrollbar-highlight-color:#fff; ?? ????scrollbar-shadow-color:#eeeeee; ?? ????scrollbar-3dlight-color:#eeeeee; ?? ????scrollbar-arrow-color:#000; ?? ????scrollbar-track-color:#fff; ?? ????scrollbar-darkshadow-color:#fff; ?? ????} ?? --> ?? </style>?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
html {scrollbar-face-color:#f6f6f6;scrollbar-highlight-color:#fff;scrollbar-shadow-color:#eeeeee;scrollbar-3dlight-color:#eeeeee;scrollbar-arrow-color:#000;scrollbar-track-color:#fff;scrollbar-darkshadow-color:#fff;}
-->
</style>
17.為什么我定義的樣式沒有作用呢
這里你無法用.aa定義到li 遇到這種情況怎么解決呢?答案是提高.aa 的優先權 比如#aa ul li.aa
Code:
Java代碼<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ?? <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/> ?? <style?type="text/css"> ?? <!-- ?? #aa?ul?li?{ ?? ????color:red ?? ????} ?? .aa?{ ?? ????color:blue ?? ????} ?? --> ?? </style> ?? <div?id="aa"> ?? <ul> ?? <li?class="aa"> ?? web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全 ?? </li> ?? </ul> ?? </div>?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
#aa ul li {color:red}
.aa {color:blue}
-->
</style>
<div id="aa">
<ul>
<li class="aa">
web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全web標準常見問題大全
</li>
</ul>
</div>
18.為什么無法定義1px左右高度的容器
IE6下這個問題是因為默認的行高造成的,解決的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px
19.為什么這個背景顏色無法顯示
Code:
Java代碼<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ?? <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/> ?? <style?type="text/css"> ?? <!--? ?? ul?{ ?? ????background:red ?? ????} ?? li?{ ?? ????float:left; ?? ????width:180px; ?? ????} ?? --> ?? </style> ?? <!--[if?lte?IE?6]> ?? <style> ?? .gainlayout?{?height:?1px;?} ?? </style> ?? <![endif]-->?? ?? <ul?class="gainlayout"> ?? <li>web標準常見問題大全</li> ?? <li>web標準常見問題大全</li> ?? <li>web標準常見問題大全</li> ?? <li>web標準常見問題大全</li> ?? <li>web標準常見問題大全</li> ?? <div?style="clear:both"></div> ?? </ul>?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
ul {background:red}
li {float:left;width:180px;}
-->
</style>
<!--[if lte IE 6]>
<style>
.gainlayout { height: 1px; }
</style>
<![endif]-->
<ul class="gainlayout">
<li>web標準常見問題大全</li>
<li>web標準常見問題大全</li>
<li>web標準常見問題大全</li>
<li>web標準常見問題大全</li>
<li>web標準常見問題大全</li>
<div style="clear:both"></div>
</ul>
IE中設置有背景色的ul并沒有顯示出來,這個屬于haslayout問題,解決的辦法也很多參考 http://www.satzansatz.de/cssd/onhavinglayout.htm
解決方法之一:
Code:
Java代碼<!--[if?lte?IE?6]> ?? <style> ?? .gainlayout?{?height:?1px;?} ?? </style> ?? <![endif]-->???? <!--[if lte IE 6]>
<style>
.gainlayout { height: 1px; }
</style>
<![endif]-->
20.怎么樣才能讓層顯示在FLASH之上呢
解決的辦法是給FLASH設置透明
Code:
<param name="wmode" value="transparent" />
21.怎樣使一個層垂直居中于瀏覽器中
這里我們使用百分比絕對定位,與外補丁負值的方法,負值的大小為其自身寬度高度除以二
Code:
Java代碼<style?type="text/css"> ?? <!--? ?? div?{ ?? ????position:absolute; ?? ????top:50%; ?? ????left:50%; ?? ????margin:-100px?0?0?-100px; ?? ????width:200px; ?? ????height:200px; ?? ????border:1px?solid?red; ?? ????} ?? --> ?? </style>?? <style type="text/css">
<!--
div {position:absolute;top:50%;left:50%;margin:-100px 0 0 -100px;width:200px;height:200px;border:1px solid red;}
-->
</style>
22 .圖片垂直與容器內
Code:
Java代碼<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ?? <style?type="text/css"> ?? <!--? ?? *?{margin:0;padding:0} ?? div?{ ?? ????width:500px; ?? ????height:500px; ?? ????border:1px?solid?#ccc; ?? ????overflow:hidden; ?? ????position:relative; ?? ????display:table-cell; ?? ????text-align:center; ?? ????vertical-align:middle ?? ????} ?? div?p?{ ?? ????position:static; ?? ????+position:absolute; ?? ????top:50% ?? ????} ?? img?{ ?? ????position:static; ?? ????+position:relative; ?? ????top:-50%;left:-50%; ?? ????width:276px; ?? ????height:110px ?? ????} ?? --> ?? </style> ?? <div><p><img?src="logo.gif"?/></p></div>?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<style type="text/css">
<!--
* {margin:0;padding:0}
div {width:500px;height:500px;border:1px solid #ccc;overflow:hidden;position:relative;display:table-cell;text-align:center;vertical-align:middle}
div p {position:static;+position:absolute;top:50%}
img {position:static;+position:relative;top:-50%;left:-50%;width:276px;height:110px}
-->
</style>
<div><p><img src="logo.gif" /></p></div>
或者使用背景圖的辦法:
Code:
background:url("logo.gif") center no-repeat;
23.如何讓div橫向排列
橫向排列DIV可以使用浮動的方式比如float:left,或者設置對象為內聯,還可以絕對定位對象等等.
Code:
Java代碼<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ?? <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/> ?? <style?type="text/css"> ?? <!--? ?? div?{ ?? ????float:left; ?? ????width:200px; ?? ????height:200px; ?? ????border:1px?solid?red ?? ????} ?? --> ?? </style> ?? <div>web標準常見問題大全</div> ?? <div>web標準常見問題大全</div> ?? <div>web標準常見問題大全</div>
1.超鏈接訪問過后hover樣式就不出現的問題
被點擊訪問過的超鏈接樣式不在具有hover和active了,很多人應該都遇到過這個問題,解決方法是改變CSS屬性的排列順序: L-V-H-A
Code:
Java代碼
2.FireFox下如何使連續長字段自動換行
眾所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我們使用JS插入 的方法來解決
Code:
Java代碼
Java代碼
3.ff下為什么父容器的高度不能自適應
在子容器加了浮動屬性后,該容器將不能自動撐開,解決方法是在標簽結束后加上一個清除浮動的元素。
Code:
Java代碼
4.IE6的雙倍邊距BUG
浮動后本來外邊距10px,但IE解釋為20px,解決辦法是加上
Code:
Java代碼
5. IE6下絕對定位的容器內文本無法正常選擇的問題
此問題在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下為什么圖片下方有空隙產生
解決這個BUG的方法也有很多,可以是改變html的排版,或者設置img 為display:block 或者設置vertical-align 屬性為vertical-align:top | bottom |middle |text-bottom
都可以解決.
7. IE6下兩個層中間怎么有間隙
這個IE的3PX BUG也是經常出現的,解決的辦法是給.right也同樣浮動 float:left 或者相對IE6定義.left margin-right:-3px;
8. list-style-image無法準確定位的問題
list-style-image的定位問題也是經常有人問的,解決的辦法一般是用li的背景模擬,這里采用相對定位的方法也可以解決。
9. LI中內容超過長度后以省略號顯示的方法
此方法適用與IE與OP瀏覽器
Code:
Java代碼
10.web標準中定義id與class有什么區別嗎
一.web標準中是不容許重復ID的,比如 div id="aa"? 不容許重復2次,而class 定義的是類,理論上可以無限重復, 這樣需要多次引用的定義便可以使用他.
二.屬性的優先級問題
ID 的優先級要高于class,看上面的例子
三.方便JS等客戶端腳本,如果在頁面中要對某個對象進行腳本操作,那么可以給他定義一個ID,否則只能利用遍歷頁面元素加上指定特定屬性來找到它,這是相對浪費時間資源,遠遠不如一個ID來得簡單.
11.如何垂直居中文本
將元素高度和行高設為一致。
Code:
Java代碼
12.如何對齊文本與文本輸入框
加上 vertical-align:middle;
Code:
Java代碼
13.為什么FF下面不能水平居中呢
FF下面設置容器的左右外補丁為auto就可以了
Code:
Java代碼
14.為什么FF下文本無法撐開容器的高度
標準瀏覽器中固定高度值的容器是不會象IE6里那樣被撐開的,那我又想固定高度,又想能被撐開需要怎樣設置呢?辦法就是去掉height設置min-height:200px;? 這里為了照顧不認識min-height的IE6 可以這樣定義:
Code:
Java代碼
15.為什么IE6下容器的寬度和FF解釋不同呢
Code:
Java代碼
問題的差別在于容器的整體寬度有沒有將邊框(border)的寬度算在其內,這里IE6解釋為200PX ,而FF則解釋為220PX,那究竟是怎么導致的問題呢?大家把容器頂部的xml去掉就會發現原來問題出在這,頂部的申明觸發了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:
Java代碼
17.為什么我定義的樣式沒有作用呢
這里你無法用.aa定義到li 遇到這種情況怎么解決呢?答案是提高.aa 的優先權 比如#aa ul li.aa
Code:
Java代碼
18.為什么無法定義1px左右高度的容器
IE6下這個問題是因為默認的行高造成的,解決的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px
19.為什么這個背景顏色無法顯示
Code:
Java代碼
IE中設置有背景色的ul并沒有顯示出來,這個屬于haslayout問題,解決的辦法也很多參考 http://www.satzansatz.de/cssd/onhavinglayout.htm
解決方法之一:
Code:
Java代碼
20.怎么樣才能讓層顯示在FLASH之上呢
解決的辦法是給FLASH設置透明
Code:
<param name="wmode" value="transparent" />
21.怎樣使一個層垂直居中于瀏覽器中
這里我們使用百分比絕對定位,與外補丁負值的方法,負值的大小為其自身寬度高度除以二
Code:
Java代碼
22 .圖片垂直與容器內
Code:
Java代碼
或者使用背景圖的辦法:
Code:
background:url("logo.gif") center no-repeat;
23.如何讓div橫向排列
橫向排列DIV可以使用浮動的方式比如float:left,或者設置對象為內聯,還可以絕對定位對象等等.
Code:
Java代碼
總結
以上是生活随笔為你收集整理的IE/Firefox中css兼容常见问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ip地址管理与子网的划分二
- 下一篇: 工行卡年费可以取消吗