秋风的萧瑟 又见湖边木叶飞

欢迎来到梁良 | LonBlog,这里记录下了我生活点点滴滴。

web标准常见问题大全 让FireFox与IE兼容

 web标准常见问题大全 让FireFox与IE兼容
1.超链接访问过后hover样式就不出现的问题
被点击访问过的超链接样式不在具有hover和active了,很多人应该都遇到过这个问题,解决方法是改变CSS属性的排列顺序: L-V-H-A
Code: 

  1. <style type="text/css">   
  2. <!--    
  3. a:link {}   
  4. a:visited {}   
  5. a:hover {}   
  6. a:active {}   
  7. -->   
  8. </style>  
Java代码
  1. <style type="text/css">  
  2. <!--   
  3. a:link {}  
  4. a:visited {}  
  5. a:hover {}  
  6. a:active {}  
  7. -->  
  8. </style>  


2.FireFox下如何使连续长字段自动换行
众所周知IE中直接使用 word-wrap:break-word 就可以了, FF中我们使用JS插入的方法来解决
Code: 

  1. <style type="text/css">   
  2. <!--    
  3. div {   
  4.     width:300px;   
  5.     word-wrap:break-word;   
  6.     border:1px solid red;   
  7. }   
  8. -->   
  9. </style>   
  10. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa   
  11. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa   
  12. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa   
  13. aaaaaaaaaaaaaaaaaaaaaaaaaaa</div>  
Java代码
  1. <style type="text/css">  
  2. <!--   
  3. div {  
  4.     width:300px;  
  5.     word-wrap:break-word;  
  6.     border:1px solid red;  
  7. }  
  8. -->  
  9. </style>  
  10. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  11. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  12. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  
  13. 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>  
Java代码
  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下为什么父容器的高度不能自适应
在子容器加了浮动属性后,该容器将不能自动撑开,解决方法是在标签结束后加上一个清除浮动的元素。
Code: 

  1. clear: both;  
Java代码
  1. clear: both;  


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

  1. display: inline  
Java代码
  1. 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: 

  1. <style type="text/css">   
  2. <! --    
  3. li {   
  4.     width: 200px;   
  5.     white-space:nowrap;   
  6.     text-overflow:ellipsis;    
  7.     -o-text-overflow:ellipsis;    
  8.     overflow: hidden;   
  9.     }   
  10. -->   
  11. </style>  
Java代码
  1. <style type="text/css">  
  2. <! --   
  3. li {  
  4.     width: 200px;  
  5.     white-space:nowrap;  
  6.     text-overflow:ellipsis;   
  7.     -o-text-overflow:ellipsis;   
  8.     overflow: hidden;  
  9.     }  
  10. -->  
  11. </style>  


10.web标准中定义id与class有什么区别吗
一.web标准中是不容许重复ID的,比如 div id="aa" 不容许重复2次,而class 定义的是类,理论上可以无限重复, 这样需要多次引用的定义便可以使用他.
二.属性的优先级问题
ID 的优先级要高于class,看上面的例子
三.方便JS等客户端脚本,如果在页面中要对某个对象进行脚本操作,那么可以给他定义一个ID,否则只能利用 遍历页面元素加上指定特定属性来找到它,这是相对浪费时间资源,远远不如一个ID来得简单.

11.如何垂直居中文本
将元素高度和行高设为一致。
Code: 

  1. <style type="text/css">   
  2. <!--    
  3. div {   
  4.     height:30px;   
  5.     line-height:30px;   
  6.     border:1px solid red   
  7.     }   
  8. -->   
  9. </style>  
Java代码
  1. <style type="text/css">  
  2. <!--   
  3. div {  
  4.     height:30px;  
  5.     line-height:30px;  
  6.     border:1px solid red  
  7.     }  
  8. -->  
  9. </style>  


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

  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>  
Java代码
  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下面不能水平居中呢
FF下面设置容器的左右外补丁为auto就可以了
Code: 

  1. <style type="text/css">   
  2. <!--    
  3. div {   
  4.     margin:0 auto;   
  5. }   
  6. -->   
  7. </style>  
Java代码
  1. <style type="text/css">  
  2. <!--   
  3. div {  
  4.     margin:0 auto;  
  5. }  
  6. -->  
  7. </style>  


14.为什么FF下文本无法撑开容器的高度
标准浏览器中固定高度值的容器是不会象IE6里那样被撑开的,那我又想固定高度,又想能被撑开需要怎样设置呢?办法就是去掉height设置 min-height:200px; 这里为了照顾不认识min-height的IE6 可以这样定义:
Code: 

  1. {   
  2. height:auto!important;   
  3. height:200px;   
  4. min-height:200px;   
  5. }  
Java代码
  1. {  
  2. height:auto!important;  
  3. height:200px;  
  4. min-height:200px;  
  5. }  


15.为什么IE6下容器的宽度和FF解释不同呢
Code: 

  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>  
Java代码
  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的相关知识,请参考:
[url]http://www.microsoft.com/china/msdn/library/webservices/asp.net/
ASPNETusStan.mspx?mfr=true[/url]

16.为什么web标准中IE无法设置滚动条颜色了
解决办法是将body换成html
Code: 

  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. html {   
  6.     scrollbar-face-color:#f6f6f6;   
  7.     scrollbar-highlight-color:#fff;   
  8.     scrollbar-shadow-color:#eeeeee;   
  9.     scrollbar-3dlight-color:#eeeeee;   
  10.     scrollbar-arrow-color:#000;   
  11.     scrollbar-track-color:#fff;   
  12.     scrollbar-darkshadow-color:#fff;   
  13.     }   
  14. -->   
  15. </style>  
Java代码
  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. html {  
  6.     scrollbar-face-color:#f6f6f6;  
  7.     scrollbar-highlight-color:#fff;  
  8.     scrollbar-shadow-color:#eeeeee;  
  9.     scrollbar-3dlight-color:#eeeeee;  
  10.     scrollbar-arrow-color:#000;  
  11.     scrollbar-track-color:#fff;  
  12.     scrollbar-darkshadow-color:#fff;  
  13.     }  
  14. -->  
  15. </style>  


17.为什么我定义的样式没有作用呢
这里你无法用.aa定义到li 遇到这种情况怎么解决呢?答案是提高.aa 的优先权 比如#aa ul li.aa
Code: 

  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. #aa ul li {   
  6.     color:red   
  7.     }   
  8. .aa {   
  9.     color:blue   
  10.     }   
  11. -->   
  12. </style>   
  13. <div id="aa">   
  14. <ul>   
  15. <li class="aa">   
  16. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web 标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题 大全web标准常见问题大全web标准常见问题大全web标准常见问题大全   
  17. </li>   
  18. </ul>   
  19. </div>  
Java代码
  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. #aa ul li {  
  6.     color:red  
  7.     }  
  8. .aa {  
  9.     color:blue  
  10.     }  
  11. -->  
  12. </style>  
  13. <div id="aa">  
  14. <ul>  
  15. <li class="aa">  
  16. web 标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题 大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标 准常见问题大全  
  17. </li>  
  18. </ul>  
  19. </div>  


18.为什么无法定义1px左右高度的容器
IE6下这个问题是因为默认的行高造成的,解决的方法也有很多,例如:overflow:hidden | zoom:0.08 | line-height:1px

19.为什么这个背景颜色无法显示

Code: 

  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>  
Java代码
  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
解决方法之一:
Code: 

  1. <!--[if lte IE 6]>   
  2. <style>   
  3. .gainlayout { height: 1px; }   
  4. </style>   
  5. <![endif]-->    
Java代码
  1. <!--[if lte IE 6]>  
  2. <style>  
  3. .gainlayout { height: 1px; }  
  4. </style>  
  5. <![endif]-->    


20.怎么样才能让层显示在FLASH之上呢
解决的办法是给FLASH设置透明
Code:
<param name="wmode" value="transparent" />

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

  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>  
Java代码
  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 .图片垂直与容器内
Code: 

  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>  
Java代码
  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>  

或者使用背景图的办法:
Code:
background:url("logo.gif") center no-repeat;

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

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

posted on 2010-04-11 00:17 梁良 阅读(314) 评论(0)  编辑  收藏 所属分类: CSS


只有注册用户登录后才能发表评论。


网站导航:
 
<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

公告

    欢迎光临

常用链接

随笔分类

随笔档案

相册

.我的网站.

友情博客

开源社区

科技博客

资料网站

最新随笔

搜索

最新评论

阅读排行榜

Powered by:
LonLeung
Copyright © 梁良

本页生成时间:毫秒