web标准常见问题整理

 

web标准常见问题整理

列举了一些常见,新手经常问的问题。举例并说明解决方法。(内容在下面对应)
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样式就不出现的问题
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. a:link {
  10. color:red
  11. }
  12. a:hover {
  13. color:blue
  14. }
  15. a:visited {
  16. color:green
  17. }
  18. a:active {
  19. color:orange
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <a href="#">
  26. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全
  27. </a>
  28. </body>
  29. </html>
复制代码
被点击访问过的超链接样式不在具有hover和active了,很多人应该都遇到过这个问题,解决方法是改变CSS属性的排列顺序: L-V-H-A

2.FF下如何使连续长字段自动换行
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:300px;
  11. word-wrap:break-word;
  12. border:1px solid red;
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div id="ff">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
  19. <script type="text/javascript">
  20. // <![CDATA[
  21. function toBreakWord(intLen){
  22. var obj=document.getElementById("ff");
  23. var strContent=obj.innerHTML;
  24. var strTemp="";
  25. while(strContent.length>intLen){
  26. strTemp+=strContent.substr(0,intLen)+" ";
  27. strContent=strContent.substr(intLen,strContent.length);
  28. }
  29. strTemp+=" "+strContent;
  30. obj.innerHTML=strTemp;
  31. }
  32. if(document.getElementById && !document.all) toBreakWord(37)
  33. // ]]>
  34. </script>
  35. </body>
  36. </html>
复制代码
众所周知IE中直接使用    word-wrap:break-word 就可以了, 这里FF中我们使用JS插入&#10;的方法来解决


3.ff下为什么父容器的高度不能自适应
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:200px;
  11. border:1px solid red
  12. }
  13. p {
  14. float:left;
  15. width:100px;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <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>
  22. </body>
  23. </html>
复制代码
为什么这个P撑不开DIV呢?解决的办法是在div 与 p 之间插入<div style="clear:both"></div>清除掉这个p的浮动.
什么?你在IE下也碰到过类似问题!那么参考:http://bbs.blueidea.com/viewthread.php?tid=2636904



4. IE6的双倍边距BUG
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. margin:0
  11. }
  12. div {
  13. float:left;
  14. margin-left:10px;
  15. width:200px;
  16. height:200px;
  17. border:1px solid red
  18. }
  19. /*]]>*/
  20. </style>
  21. </head>
  22. <body>
  23. <div>
  24. <a href="#">
  25. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全
  26. </a>
  27. </div>
  28. </body>
  29. </html>
复制代码
浮动后本来外边距10px,但IE解释为20px,解决办法是加上display:inline

5. IE6下绝对定位的容器内文本无法正常选择的问题
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:100px;
  12. left:100px;
  13. width:200px;
  14. height:200px;
  15. border:1px solid red
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <a href="#">
  23. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全
  24. </a>
  25. </div>
  26. </body>
  27. </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下为什么图片下方有空隙产生
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. border:1px solid red;
  11. background:orange;
  12. }
  13. img {
  14. width:276px;
  15. height:110px;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <div>
  22. <img src="http://www.google.com/intl/en_ALL/images/logo.gif" alt="google" />
  23. </div>
  24. </body>
  25. </html>
复制代码
解决这个BUG的方法也有很多,可以是改变html的排版,或者定义img 为display:block
或者定义vertical-align属性值为vertical-align:top | bottom |middle |text-bottom
还可以设置父容器的字体大小为零,font-size:0



7. IE6下这两个层中间怎么有间隙
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. .left {
  10. float:left;
  11. width:100px;
  12. height:100px;
  13. background:red
  14. }
  15. .right {
  16. width:100px;
  17. height:100px;
  18. background:orange;
  19. overflow:hidden;
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <div class="left">aaaaaa</div>
  26. <div class="right">aaaaaa</div>
  27. </body>
  28. </html>
复制代码
这个IE的3PX BUG也是经常出现的,解决的办法是给.right也同样浮动 float:left 或者相对IE6定义.left margin-right:-3px;


8. list-style-image无法准确定位的问题
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. li {
  10. list-style:url("http://bbs.blueidea.com/attachments/2006/11/10/arrowb_kJrcZheJmiIF.gif");
  11. }
  12. li a {
  13. position:relative;
  14. top:-5px;
  15. font:12px/25px 宋体;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <ul>
  22. <li><a href="#">web标准常见问题大全</a></li>
  23. <li><a href="#">web标准常见问题大全</a></li>
  24. <li><a href="#">web标准常见问题大全</a></li>
  25. <li><a href="#">web标准常见问题大全</a></li>
  26. <li><a href="#">web标准常见问题大全</a></li>
  27. </ul>
  28. </body>
  29. </html>
复制代码
这个list-style-image的定位问题也是经常有人问的,解决的办法一般是用li的背景模拟,这里采用相对定位的方法也可以解决

9. LI中内容超过长度后以省略号显示的方法


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. li {
  10. width:200px;
  11. white-space:nowrap;
  12. text-overflow:ellipsis;
  13. -o-text-overflow:ellipsis;
  14. overflow: hidden;
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <ul>
  21. <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
  22. <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
  23. <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
  24. <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
  25. <li><a href="#">web标准常见问题大全web标准常见问题大全</a></li>
  26. </body>
  27. </html>
复制代码



此方法适用与IE与OP浏览器


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


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. #aa {
  10. color:red
  11. }
  12. .aa {
  13. color:blue
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div id="aa" class="aa">
  20. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  21. </div>
  22. </body>
  23. </html>
复制代码


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. .a {
  10. color:orange
  11. }
  12. .b {
  13. background:#eee
  14. }
  15. .c {
  16. border:1px solid red
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div class="a b c">aaaaaaaa</div>
  23. </body>
  24. </html>
复制代码


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



11.如何垂直居中文本


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. height:30px;
  11. line-height:30px;
  12. border:1px solid red
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div>web标准常见问题大全</div>
  19. </body>
  20. </html>
复制代码



给容器设置一个与其高度相同的行高就可以了


12.如何对齐文本与文本输入筐


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. input {
  10. width:200px;
  11. height:30px;
  12. border:1px solid red;
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <input type="text" />aaaaaaaaaaaaaaaaaa
  19. </body>
  20. </html>
复制代码



遇到此种问题,设置文本框的    vertical-align:middle 就可以了


13.为什么FF下面不能水平居中呢


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. text-align:center;
  11. }
  12. div {
  13. margin:0 auto;
  14. width:500px;
  15. height:200px;
  16. border:1px solid red
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div></div>
  23. </body>
  24. </html>
复制代码



FF下面设置容器的左右外补丁为auto就可以了


14.为什么FF下文本无法撑开容器的高度
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:200px;
  11. height:200px;
  12. border:1px solid red
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <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>
  19. </body>
  20. </html>
复制代码
标准浏览器中固定高度值的容器是不会象IE6里那样被撑开的,那我又想固定高度,又想能被撑开需要怎样设置呢?办法就是去掉height设置min-height:200px;  这里为了照顾不认识min-height的IE6 可以这样定义:
{
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. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  4. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  5. <meta http-equiv="content-language" content="zh-cn" />
  6. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  7. <title>blueidea</title>
  8. <style type="text/css">
  9. /*<![CDATA[*/
  10. div {
  11. cursor:pointer;
  12. width:200px;
  13. height:200px;
  14. border:10px solid red
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <div onclick="alert(this.offsetWidth)">web标准常见问题大全</div>
  21. <hr/>
  22. </body>
  23. </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无法设置滚动条颜色了
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. body {
  10. scrollbar-face-color:#f6f6f6;
  11. scrollbar-highlight-color:#fff;
  12. scrollbar-shadow-color:#eeeeee;
  13. scrollbar-3dlight-color:#eeeeee;
  14. scrollbar-arrow-color:#000;
  15. scrollbar-track-color:#fff;
  16. scrollbar-darkshadow-color:#fff;
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <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/>
  23. </body>
  24. </html>
复制代码
解决办法是将body换成html


17.为什么我定义的样式没有作用呢
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. #aa ul li {
  10. color:red
  11. }
  12. .aa {
  13. color:blue
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div id="aa">
  20. <ul>
  21. <li class="aa">
  22. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全
  23. </li>
  24. </ul>
  25. </div>
  26. </body>
  27. </html>
复制代码
这里你无法用.aa定义到li 遇到这种情况怎么解决呢?答案是提高.aa 的优先权 比如#aa ul li.aa 优先权相关文章参考-baidu搜索关键词: CSS的优先权


18.为什么无法定义1px左右高度的容器
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. background:red;
  11. }
  12. /*]]>*/
  13. </style>
  14. </head>
  15. <body>
  16. <div> </div>
  17. </body>
  18. </html>
复制代码
IE6下这个问题是因为默认的行高造成的,解决的方法也有很多,例如: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. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. ul {
  10. background:red
  11. }
  12. li {
  13. float:left;
  14. width:180px;
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <ul>
  21. <li>web标准常见问题大全</li>
  22. <li>web标准常见问题大全</li>
  23. <li>web标准常见问题大全</li>
  24. <li>web标准常见问题大全</li>
  25. <li>web标准常见问题大全</li>
  26. <div style="clear:both"></div>
  27. </ul>
  28. </body>
  29. </html>
复制代码


IE中设置有背景色的ul并没有显示出来,这个属于haslayout问题,解决的办法也很多参考:http://bbs.blueidea.com/viewthread.php?tid=2636904

20.怎么样才能让层显示在FLASH之上呢
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:20px;
  12. left:20px;
  13. width:200px;
  14. height:200px;
  15. background:red
  16. }
  17. object {
  18. width:500px;
  19. height:100px;
  20. }
  21. /*]]>*/
  22. </style>
  23. </head>
  24. <body>
  25. <div>
  26. web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全web标准常见问题大全
  27. </div>
  28. <object type="application/x-shockwave-flash" data="http://gg.blueidea.com/2005/www/m533-104.swf">
  29. <param name="movie" value="http://gg.blueidea.com/2005/www/m533-104.swf" />
  30. </object>
  31. </body>
  32. </html>
复制代码


解决的办法是给FLASH设置透明<param name="wmode" value="transparent" />或者<param name="wmode" value="opaque" />


21.怎样使一个层垂直居中于浏览器中


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:50%;
  12. left:50%;
  13. margin:-100px 0 0 -100px;
  14. width:200px;
  15. height:200px;
  16. border:1px solid red;
  17. }
  18. /*]]>*/
  19. </style>
  20. </head>
  21. <body>
  22. <div>web标准常见问题大全</div>
  23. </body>
  24. </html>
复制代码
这里我们使用百分比绝对定位,与外补丁负值的方法,负值的大小为其自身宽度高度除以二


22 .图片垂直于容器内

参考:http://bbs.blueidea.com/thread-2666987-1-1.html


23.如何让三列横向排列
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. float:left;
  11. margin:1px;
  12. width:200px;
  13. height:200px;
  14. background:orange
  15. }
  16. /*]]>*/
  17. </style>
  18. </head>
  19. <body>
  20. <div></div>
  21. <div></div>
  22. <div></div>
  23. </body>
  24. </html>
复制代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. position:absolute;
  11. top:50%;
  12. left:50%;
  13. margin:-100px 0 0 -300px;
  14. }
  15. /*]]>*/
  16. </style>
  17. </head>
  18. <body>
  19. <div style="background:#404040;width:200px;height:200px;">1</div>
  20. <div style="background:#FD7C03;width:200px;height:200px;margin:-100px 0 0 -100px;">2</div>
  21. <div style="background:#eee;width:200px;height:200px;margin:-100px 0 0 100px;">3</div>
  22. </body>
  23. </html>
复制代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. span {
  10. margin:1px;
  11. display:-moz-inline-box;
  12. display:inline-block;
  13. width:300px;
  14. height:200px;
  15. background:orange;
  16. }
  17. /*]]>*/
  18. </style>
  19. </head>
  20. <body>
  21. <span></span>
  22. <span></span>
  23. <span></span>
  24. </body>
  25. </html>
复制代码
横向排列DIV可以使用浮动的方式比如float:left,或者用内联方式,还可以绝对定位对象等等



24.通用的加入收藏夹代码
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. function bookmark(){
  4. var title=document.title
  5. var url=document.location.href
  6. if (window.sidebar) window.sidebar.addPanel(title, url,"");
  7. else if( window.opera && window.print ){
  8. var mbm = document.createElement('a');
  9. mbm.setAttribute('rel','sidebar');
  10. mbm.setAttribute('href',url);
  11. mbm.setAttribute('title',title);
  12. mbm.click();}
  13. else if( document.all ) window.external.AddFavorite( url, title);
  14. }
  15. // ]]>
  16. </script>
  17. <a href="javascript:bookmark()">加入收藏夹</a>
复制代码
经常有朋友说他的加入收藏夹代码只支持IE,上面的例子可以很好的解决这个问题,在IE6-7. FF2.0  OP9.0中测试通过


25.复制到系统剪贴板之IE,ff兼容版
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <script type="text/javascript">
  3. // <![CDATA[
  4. function copy_clip(copy){
  5. if (window.clipboardData){
  6. window.clipboardData.setData("Text", copy);}
  7. else if (window.netscape){
  8. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  9. var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  10. if (!clip) return;
  11. var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  12. if (!trans) return;
  13. trans.addDataFlavor('text/unicode');
  14. var str = new Object();
  15. var len = new Object();
  16. var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  17. var copytext=copy;
  18. str.data=copytext;
  19. trans.setTransferData("text/unicode",str,copytext.length*2);
  20. var clipid=Components.interfaces.nsIClipboard;
  21. if (!clip) return false;
  22. clip.setData(trans,null,clipid.kGlobalClipboard);}
  23. alert("已复制"+copy)
  24. return false;
  25. }
  26. // ]]>
  27. </script>
  28. <h1>请另存代码测试</h1>
  29. <input type="text" id="ff" value="www.blueidea.com" /><button onclick="copy_clip(document.getElementById('ff').value)">复制
  30. </button>
复制代码
26.javascript为FF设置首页
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <script type="text/javascript">
  3. // <![CDATA[
  4. function setHomePage(){
  5. if(window.netscape){
  6. try {
  7. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  8. }
  9. catch (e) {}}
  10. var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  11. prefs.setCharPref('browser.startup.homepage','http://www.blueidea.com');
  12. }
  13. // ]]>
  14. </script>
  15. <a href="#" onclick="setHomePage()">设置首页</a>
复制代码
27.IE6使用滤镜使PNG图片透明后,容器内链接失效的问题。
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. div {
  10. width:401px;
  11. height:223px;
  12. filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='http://bbs.blueidea.com/attachments/2006/9/11/bg_nT9Vi2i45To0.png')
  13. }
  14. /*]]>*/
  15. </style>
  16. </head>
  17. <body>
  18. <div><a href="#">27.IE6使用滤镜使PNG图片透明后,容器内链接失效的问题。</a></div>
  19. </body>
  20. </html>
复制代码
解决方法是为链接定义一个相对定位属性。position:relative


28.禁用文本框中文输入法的通用方法。
  1. <div>验证码<input type="text" style="ime-mode:disabled"/></div>
复制代码

IE可以用ime-mode:disabled,firefox3也开始支持IE的这一私有属性


对于其他不支持的浏览器可以用如下方法模拟
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
  3. <head profile="http://www.w3.org/2000/08/w3c-synd/#">
  4. <meta http-equiv="content-language" content="zh-cn" />
  5. <meta http-equiv="content-type" content="text/html;charset=gb2312" />
  6. <title>blueidea</title>
  7. <style type="text/css">
  8. /*<![CDATA[*/
  9. input,textarea {
  10. width:300px;
  11. height:20px;
  12. border:1px solid
  13. }
  14. textarea {
  15. height:150px
  16. }
  17. #pw {
  18. opacity:0;
  19. display:block;
  20. position:relative;
  21. margin-top:-24px
  22. }
  23. #tt,#pw {
  24. width:100px
  25. }
  26. /*]]>*/
  27. </style>
  28. </head>
  29. <body>
  30. <table>
  31. <tr>
  32. <td>标题</td>
  33. <td><input type="text"/></td>
  34. </tr>
  35. <tr>
  36. <td>内容</td>
  37. <td><textarea></textarea></td>
  38. </tr>
  39. <tr>
  40. <td>验证码</td>
  41. <td><input type="text" id="tt"/><input type="password" id="pw"/></td>
  42. </tr>
  43. </table>
  44. <script type="text/javascript">
  45. // <![CDATA[
  46. var ee = document.getElementById('pw');
  47. ee.onkeyup = function p() {
  48. document.getElementById('tt').value = ee.value;
  49. }
  50. // ]]>
  51. </script>
  52. </body>
  53. </html>
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值