~~圆角是比较常用的css3属性,但是ie6-8并不支持圆角,可用border-radius.htc  html组件实现圆角, border-radius.htc内部应用vml进行了重绘

border-radius.htc:

  1. --Do not remove this if you are using--
  2. Original Author: Remiz Rahnas
  3. Original Author URL: http://www.htmlremix.com
  4. Published date: 2008/09/24
  5.  
  6. Changes by Nick Fetchak:
  7. - IE8 standards mode compatibility
  8. - VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
  9. Published date : 2009/11/18
  10.  
  11. <public:attach event="oncontentready" onevent="oncontentready('v08vnSVo78t4JfjH')" />
  12. <script type="text/javascript">
  13.  
  14. // findPos() borrowed from http://www.quirksmode.org/js/findpos.html
  15. function findPos(obj) {
  16. var curleft = curtop = 0;
  17.  
  18. if (obj.offsetParent) {
  19. do {
  20. curleft += obj.offsetLeft;
  21. curtop += obj.offsetTop;
  22. } while (obj = obj.offsetParent);
  23. }
  24.  
  25. return({
  26. 'x': curleft,
  27. 'y': curtop
  28. });
  29. }
  30.  
  31. function oncontentready(classID) {
  32. if (this.className.match(classID)) { return(false); }
  33.  
  34. if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }
  35.  
  36. this.className = this.className.concat(' ', classID);
  37. var arcSize = Math.min(parseInt(this.currentStyle['-moz-border-radius'] ||
  38. this.currentStyle['-webkit-border-radius'] ||
  39. this.currentStyle['border-radius'] ||
  40. this.currentStyle['-khtml-border-radius']) /
  41. Math.min(this.offsetWidth, this.offsetHeight), 1);
  42. var fillColor = this.currentStyle.backgroundColor;
  43. var fillSrc = this.currentStyle.backgroundImage.replace(/^url\("(.+)"\)$/, '$1');
  44. var strokeColor = this.currentStyle.borderColor;
  45. var strokeWeight = parseInt(this.currentStyle.borderWidth);
  46. var stroked = 'true';
  47. if (isNaN(strokeWeight)) {
  48. strokeWeight = 0;
  49. strokeColor = fillColor;
  50. stroked = 'false';
  51. }
  52.  
  53. this.style.background = 'transparent';
  54. this.style.borderColor = 'transparent';
  55.  
  56. // Find which element provides position:relative for the target element (default to BODY)
  57. var el = this;
  58. var limit = 100, i = 0;
  59. while ((typeof(el) != 'unknown') && (el.currentStyle.position != 'relative') && (el.tagName != 'BODY')) {
  60. el = el.parentElement;
  61. i++;
  62. if (i >= limit) { return(false); }
  63. }
  64. var el_zindex = parseInt(el.currentStyle.zIndex);
  65. if (isNaN(el_zindex)) { el_zindex = 0; }
  66. //alert('got tag '+ el.tagName +' with pos '+ el.currentStyle.position);
  67.  
  68. var rect_size = {
  69. 'width': this.offsetWidth - strokeWeight,
  70. 'height': this.offsetHeight - strokeWeight
  71. };
  72. var el_pos = findPos(el);
  73. var this_pos = findPos(this);
  74. this_pos.y = this_pos.y + (0.5 * strokeWeight) - el_pos.y;
  75. this_pos.x = this_pos.x + (0.5 * strokeWeight) - el_pos.x;
  76.  
  77. var rect = document.createElement('v:roundrect');
  78. rect.arcsize = arcSize +'px';
  79. rect.strokecolor = strokeColor;
  80. rect.strokeWeight = strokeWeight +'px';
  81. rect.stroked = stroked;
  82. rect.style.display = 'block';
  83. rect.style.position = 'absolute';
  84. rect.style.top = this_pos.y +'px';
  85. rect.style.left = this_pos.x +'px';
  86. rect.style.width = rect_size.width +'px';
  87. rect.style.height = rect_size.height +'px';
  88. rect.style.antialias = true;
  89. rect.style.zIndex = el_zindex - 1;
  90.  
  91. var fill = document.createElement('v:fill');
  92. fill.color = fillColor;
  93. fill.src = fillSrc;
  94. fill.type = 'tile';
  95.  
  96. rect.appendChild(fill);
  97. el.appendChild(rect);
  98.  
  99. var css = el.document.createStyleSheet();
  100. css.addRule("v\\:roundrect", "behavior: url(#default#VML)");
  101. css.addRule("v\\:fill", "behavior: url(#default#VML)");
  102.  
  103. isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
  104. // IE6 doesn't support transparent borders, use padding to offset original element
  105. if (isIE6 && (strokeWeight > 0)) {
  106. this.style.borderStyle = 'none';
  107. this.style.paddingTop = parseInt(this.currentStyle.paddingTop || 0) + strokeWeight;
  108. this.style.paddingBottom = parseInt(this.currentStyle.paddingBottom || 0) + strokeWeight;
  109. }
  110.  
  111. if (typeof(window.rounded_elements) == 'undefined') {
  112. window.rounded_elements = new Array();
  113.  
  114. if (typeof(window.onresize) == 'function') { window.previous_onresize = window.onresize; }
  115. window.onresize = window_resize;
  116. }
  117. this.element.vml = rect;
  118. window.rounded_elements.push(this.element);
  119. }
  120.  
  121. function window_resize() {
  122. if (typeof(window.rounded_elements) == 'undefined') { return(false); }
  123.  
  124. for (var i in window.rounded_elements) {
  125. var el = window.rounded_elements[i];
  126.  
  127. var strokeWeight = parseInt(el.currentStyle.borderWidth);
  128. if (isNaN(strokeWeight)) { strokeWeight = 0; }
  129.  
  130. var parent_pos = findPos(el.vml.parentNode);
  131. var pos = findPos(el);
  132. pos.y = pos.y + (0.5 * strokeWeight) - parent_pos.y;
  133. pos.x = pos.x + (0.5 * strokeWeight) - parent_pos.x;
  134.  
  135. el.vml.style.top = pos.y +'px';
  136. el.vml.style.left = pos.x +'px';
  137. }
  138.  
  139. if (typeof(window.previous_onresize) == 'function') { window.previous_onresize(); }
  140. }
  141. </script>
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <style type="text/css">
  4. .d1{-webkit-border-radius:5px; border:3px solid #f00; -moz-border-radius:5px; width:300px; height:300px; background:#aaa; border-radius:5px; behavior:url(htc/border-radius.htc);} //注意htc文件的相对路径是 相对html文件的
  5. </style>
  6. </head>
  7.  
  8. <body>
  9. <div class="d1" id="d1"></div>
  10. </body>
  11. </html>

border-radius.htc为ie6-8实现圆角的更多相关文章

  1. 使IE6同样支持圆角效果

    之前写到过,IE6不支持:hover效果的解决办法,其它这个跟它一样.IE6(7/8)不支持border-radius属性,所以其中的圆角效果显示不出来,可以通过引用ie-css3.htc的方法解决. ...

  2. CSS魔法堂:重拾Border之——不仅仅是圆角

    前言  当CSS3推出border-radius属性时我们是那么欣喜若狂啊,一想到终于不用再添加额外元素来模拟圆角了,但发现border-radius还分水平半径和垂直半径,然后又发现border-t ...

  3. WPF 采用Border创建圆角

    通过设置可以创建圆角border的CornerRadius属性其边框呈现圆角样式 代码: <Border Height="50" Background="Red&q ...

  4. ie6兼容问题汇总

    这几天在查找和解决网页在ie6下的兼容性问题花了我不少的时间,参考了网上的一些解决方法和自己做出来比较有效果的给大家参考一下,也方便我日后再用到: 1.IE的cache设置为Every visit t ...

  5. IE6兼容性问题及IE6常见bug详细汇总

    转载地址:http://www.jb51.net/css/76894.html 1.IE6怪异解析之padding与border算入宽高 原因:未加文档声明造成非盒模型解析 解决方法:加入文档声明&l ...

  6. IE6 一些兼容性问题及处理方法

    1.IE6怪异解析之padding与border算入宽高 原因:未加文档声明造成非盒模型解析 解决方法:加入文档声明<!doctype html> 2.IE6在块元素.左右浮动.设定mar ...

  7. 重温CSS:Border属性

    边界是众所周知的,有什么新的东西吗?好吧,我敢打赌,在这篇文章中,有很多你不看永远不知道的东西! 不仅可以用CSS3来创建圆角,使用原有CSS一样可以显示自定义图形.这是正确的(有待考究):在过去,没 ...

  8. IE6常见bug整理

    By Diaoyude  | 发布时间: 09-08 09:47  | Hits:1,253 | Post in: WEB前端 , Div-Css 针对IE6常见的一些ie6bug,ie6png,E6 ...

  9. CSS hacker(兼容IE6、7、8)

    <meta http-equiv="X-UA-Compatible"  content="IE=edge,chrome=1">这行代码是永远以最新的 ...

  10. ie6常见的兼容性

    1.IE6怪异解析之padding与border算入宽高 原因:未加文档声明造成非盒模型解析 解决方法:加入文档声明<!doctype html> 2.IE6在块元素.左右浮动.设定mar ...

随机推荐

  1. BZOJ 1635: [Usaco2007 Jan]Tallest Cow 最高的牛

    题目 1635: [Usaco2007 Jan]Tallest Cow 最高的牛 Time Limit: 5 Sec  Memory Limit: 64 MB Description FJ's N ( ...

  2. 吃透C#集合~大话目录

    最近买了一本<C#数据结构>的书,这种书确实少见,一般的数据结构都是采用C,C++来实现的,C#可以说是稀有了,呵呵,书写的不错,把C#的核心Collections介绍了一个透彻,对于我来 ...

  3. 第八届河南省赛C.最少换乘(最短路建图)

    C.最少换乘 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 94  Solved: 25 [Submit][Status][Web Board] De ...

  4. shell编程之文本与日志过滤

    1:grep命令: grep -v  "char"  file_name 匹配不包括"char"的文本 grep -n -w "char" ...

  5. XML DOM 节点

    来自:w3cschool菜鸟教程 在 DOM 中,XML 文档中的每个成分都是一个节点. DOM 节点 根据 DOM,XML 文档中的每个成分都是一个节点. DOM 是这样规定的: 整个文档是一个文档 ...

  6. superMap Object 属性查看的一点代码

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. C#WebService 客户端通过Http调用请求(转)

    1.webservice帮助类 public class WebServiceHelper    {               public static string CallServiceByG ...

  8. JavaSE_ 多线程 总目录(23~24)

    JavaSE学习总结第23天_多线程123.01 多线程程序的引入23.02 进程概述及多进程的意义23.03 线程概述及多线程的意义23.04 并行和并发的区别23.05 Java程序运行原理和JV ...

  9. Vmware虚拟机时间不准问题

    测试程序时碰到虚拟机经常时间不准,深受困扰,后来发现虚拟机有一个设置可以同步虚拟机和宿主机的时间: 该功能需要vmware tools安装成功才能有效.vmware tools的安装就不多细说了,至于 ...

  10. 射频识别技术漫谈(19)——Desfire的3次握手认证和段密码生成

    3次握手认证并生成临时的通讯密钥在通讯技术中的应用非常普遍,Mifare Desfire也使用了这种成熟的认证加密方法.Desfire在卡片数据传输前使用DES或3DES进行3次握手认证,认证成功一方 ...