读书人

火狐狸与IE兼容性总结

发布时间: 2012-09-03 09:48:39 作者: rapoo

火狐与IE兼容性总结

from:http://www.okajax.com/a/200909/ff_ie.html

?

兼容性一直都是个令人头痛的问题,下面简单总结火狐与IE的兼容性问题。

1. 超链接访问过后hover样式就不出现的问题

  • <style?type="text/css"> ?
  • ????<!--? ?
  • ????????a:link?{} ?
  • ????????a:visited?{} ?
  • ????????a:hover?{} ?
  • ????????a:active?{} ?
  • ????-->???? ?
  • </style>?

    2. FireFox下如何使连续长字段自动换行

  • <style?type="text/css">?
  • <!--? ?
  • ????div?{ ?
  • ????????width:300px; ?
  • ????????word-wrap:break-word; ?
  • ????????border:1px?solid?red; ?
  • ????} ?
  • -->?
  • </style>?
  • <div?id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
  • aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
  • aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
  • 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>?

    3.ff下为什么父容器的高度不能自适应

  • clear:both;?

    4.IE6的双倍边距BUG
    ? 浮动后本来外边距10px,但IE解释为20px,解决办法是加上

    1. display:?inline?

    5. IE6下绝对定位的容器内文本无法正常选择
    ?? 此问题在IE6、7中存在,解决问题的办法是让IE进入到qurks mode。关于qurks mode的相关知识,请参考:

  • <style?type="text/css">???? ?
  • ?<!?--????? ?
  • ??li?{???? ?
  • ????width:?200px;???? ?
  • ????white-space:nowrap;???? ?
  • ????text-overflow:ellipsis;????? ?
  • ????-o-text-overflow:ellipsis;????? ?
  • ????overflow:?hidden;???? ?
  • ????}???? ?
  • ?-->???? ?
  • </style>?


    10.web标准中定义id与class有什么区别吗

  • <style?type="text/css"> ?
  • ?<!--? ?
  • ??div{ ?
  • ???height:30px; ?
  • ???line-height:30px; ?
  • ???border:1px?solid?red?
  • ??} ?
  • ?--> ?
  • </style>?

    12.如何对齐文本与文本输入框
    ? 加上 vertical-align:middle;?

    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下面不能水平居中呢

  • <style?type="text/css"> ?
  • ??<!--? ?
  • ???div{ ?
  • ???????margin:0?auto; ?
  • ???} ?
  • ??--> ?
  • </style> ?

    14.FF下文本无法撑开容器的高度

  • { ?
  • ???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. <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)的宽度算在其内,这里IE6解释为200PX ,而FF则解释为220PX,那究竟是怎么导致的问题呢?大家把容器顶部的xml去掉就会发现原来问题出在这,顶部的申明触发了IE的qurks mode,关于qurks mode、standards mode的相关知识,请参考:?
    ???

  • <!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.??? 为什么我定义的样式没有作用呢

  • <!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标准常见问题大全 ?
  • </li>?
  • </ul>?
  • </div>?

    18.??? IE6无法定义1px左右高度的容器

  • 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. <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

  • <!--[if?lte?IE?6]>?
  • <style>???? ?
  • .gainlayout?{?height:?1px;?}???? ?
  • </style>???? ?
  • <![endif]-->????? ?
  • <!--[if?lte?IE?6]>?
  • <style>?
  • .gainlayout?{?height:?1px;?} ?
  • </style>?
  • <![endif]-->?

    20.??? 怎么样才能让层显示在FLASH之上呢
    ??? 解决的办法是给FLASH设置透明?

    1. <param?name="wmode"?value="transparent"?/>??

    21.??? 怎样使一个层垂直居中于浏览器中
    ??? 这里我们使用百分比绝对定位,与外补丁负值的方法,负值的大小为其自身宽度高度除以二?

    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.??? 图片垂直与容器内?

    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>?

    或者使用背景图的办法:?

    1. background:url("logo.gif")?center?no-repeat;?

    23.??? 如何让div横向排列
    ??? 横向排列DIV可以使用浮动的方式比如float:left,或者设置对象为内联,还可以绝对定位对象等等.?

    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. ?
    16. ?
    17. <div>web标准常见问题大全</div>?

    24? Firefox 关于DIV高度无法自适应的两种解决
    ??? 如果设置了一个DIV的高度,当DIV里实际内容大于所设高度,ie会自动拉伸以适应DIV容器大小,ff会固—IV的高度,超过部分超出DIV底线以外,
    ??? 出现和下面的内容重叠的现象。如果不给DIV设置高度,在Firefox中将不回因为里面的内容而撑开,而IE中就会自动根据内容撑开
    ??? 解决方案:
    ??? 1、在DIV内部的最后追加clear:both样式

    1. <div?style="background-color:#FF0000;">?
    2. ????<div?style="float:left;?height:200px">Jmedia?Design</div>?
    3. ????<div?style="float:right;?height:800px">www.jmedia.cn</div>?
    4. ????<div?style="clear:both"></div>?
    5. </div>?

    ??? 2、对DIV使用overflow:auto;

    1. <div?style="overflow:auto;">?
    2. ????<div?style="float:left;?background-color:#000000;height:200px">1111111111</div>?
    3. ????<div?style="float:right;background-color:#000000;?height:300px"">2222222222</div>?
    4. </div>?

  • 读书人网 >Web前端

    热点推荐