對(duì)三種瀏覽器不兼容的解決方案: 第一種: !important 來(lái)解決,因?yàn)镕irefox和IE7認(rèn)識(shí)!important,而IE6不認(rèn)識(shí)! 如下面,使用時(shí)要注意順序,不要用反了。 <div style="color: black !important; color: white;"> firefox中顯示為黑色文字,IE6中顯示為白色文字 </div> <div style="color: white !important; color: black;"> firefox中顯示為白色文字,IE6中顯示為黑色文字 </div> 第二種: IE7已經(jīng)認(rèn)識(shí)!important ,而且它跟IE6之間也存在一些差異。所以,可以針對(duì)它們寫(xiě)三個(gè)不同的樣式, 下面分別給出IE6\IE7\Firefox的hack代碼: #example { color: #333; } /* Firefox */ * html #example { color: #666; } /* IE6 */ *+html #example { color: #999; } /* IE7 */ <div id="example">測(cè)試……div> 或者 .example { color: #333; } /* Firefox */ * html .example { color: #666; } /* IE6 */ *+html .example { color: #999; } /* IE7 */ <div class="example">測(cè)試……div> 那么在Firefox下字體顏色顯示為#333,IE6下字體顏色顯示為#666,IE7下字體顏色顯示為#999,他們之間互不干擾。 三種瀏覽器之間的區(qū)別: 1. margin: FF下設(shè)置margin-left, margin-right 為auto 時(shí)已經(jīng)居中, IE 不行 2. text-align: FF下body設(shè)置text-align 時(shí), div 需要設(shè)置margin: auto(主要是 margin-left,margin-right) 方可居中 3. padding width height: FF下設(shè)置padding 后, div會(huì)增加height 和width的大小, 但I(xiàn)E 不會(huì), 所以需要用!important 多設(shè)一個(gè)height 和width 4. !important: FF和IE7: 支持!important, IE6 則忽略, 可用 !important 為FireFox 和IE7特別設(shè)置樣式 5. vertical-align: div的垂直居中問(wèn)題: vertical-align:middle; 將行距增加到和整個(gè)DIV一樣高 line-height:200px; 然后插入文字,就垂直居中了。缺點(diǎn)是要控制內(nèi)容不要換行 6.cursor: pointer 可以同時(shí)在 IE FF 中顯示游標(biāo)手指狀, hand 僅 IE 可以 7. a: FF鏈接加邊框和背景色,需設(shè)置 display: block, 同時(shí)設(shè)置 float: left 保證不換行。 參照menubar, 給 a 和 menubar 設(shè)置高度是為了避免底邊顯示錯(cuò)位, 若不設(shè) height, 可以在 menubar 中插入一個(gè)空格 8. ul標(biāo)簽在FF中默認(rèn)是有padding值的,而在IE中只有margin有值所以先定義 ul{margin:0;padding:0;}就能解決大部分問(wèn)題 9. select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; } 這個(gè)是在越出長(zhǎng)度后會(huì)自行的截掉多出部分的文字,并以省略號(hào)結(jié)尾,很好的一個(gè)技術(shù)。只是目前FF并不支持。 |
聯(lián)系客服