html5中文学习网

您的位置: 首页 > CSS3技术 » 正文

兼容所有浏览器的CSS3圆角..

[ ] 已经帮助:人解决问题

  解决CSS3圆角兼容所有浏览器的方法,如何在IE浏览器中使用CSS3的border-radius属性实现圆角HTML元素的问题。你或许知道CSS3的border-radius 属性被Safari、Firefox和Chrome等浏览器原生支持,但是由于某些原因IE并不支持它。mB9HTML5中文学习网 - HTML5先行者学习网

 mB9HTML5中文学习网 - HTML5先行者学习网

        那么要想在IE中实现圆角,你不得不使用一些技巧,比如使用带有背景图片的CSS类。mB9HTML5中文学习网 - HTML5先行者学习网

       mB9HTML5中文学习网 - HTML5先行者学习网

        而我知道的在各个浏览器中实现圆角的较简单快速的方案是结合CSS3和JavaScript。CurvyCorners是一个为HTML元素创建漂亮的圆角的免费JavaScript库。效果如下:mB9HTML5中文学习网 - HTML5先行者学习网

mB9HTML5中文学习网 - HTML5先行者学习网

        该脚本的最大优势是可以在Safari/Chrome/Firefox中使用原生的CSS3属性(通过-webkit-border-radius-moz-border-radius私有属性分别支持)而在IE和Opera中使用JavaScript。mB9HTML5中文学习网 - HTML5先行者学习网

       mB9HTML5中文学习网 - HTML5先行者学习网

        你所需要做的就是在页面中引入curvycorners.js:mB9HTML5中文学习网 - HTML5先行者学习网

		<script type="text/javascript" src="curvycorners.js"></script>

然后定义以下样式:mB9HTML5中文学习网 - HTML5先行者学习网

		.roundedCorners{
width: 220px;
padding: 10px;
background-color: #DDEEF6;
border:1px solid #DDEEF6;
 
/* Do rounding (native in Safari, Firefox and Chrome) */
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
 
}

然后在上面的样式后面定义以下代码:mB9HTML5中文学习网 - HTML5先行者学习网

		<script type="text/JavaScript">
addEvent(window, 'load', initCorners);
function initCorners() {
var setting = {
tl: { radius: 6 },
tr: { radius: 6 },
bl: { radius: 6 },
br: { radius: 6 },
antiAlias: true
}
curvyCorners(setting, ".roundedCorners");
}</script>

        tl, tr, bl, br分别是:左上角(top-left)、右上角(top-right)、左下角(bottom-left)、右下角(bottom-right)。mB9HTML5中文学习网 - HTML5先行者学习网

 mB9HTML5中文学习网 - HTML5先行者学习网

        如果你有不同的CSS类(例如roundedCorners、roundedCorners_1、roundedCorners_2等)你可以像这样在前面的代码中定义:mB9HTML5中文学习网 - HTML5先行者学习网

		...
curvyCorners(setting, ".roundedCorners");
curvyCorners(setting, ".roundedCorners_1");
curvyCorners(setting, ".roundedCorners_2");
...

HTML代码如下:mB9HTML5中文学习网 - HTML5先行者学习网

<div class="roundedCorners"> </div>mB9HTML5中文学习网 - HTML5先行者学习网

mB9HTML5中文学习网 - HTML5先行者学习网
mB9HTML5中文学习网 - HTML5先行者学习网
  mB9HTML5中文学习网 - HTML5先行者学习网

 mB9HTML5中文学习网 - HTML5先行者学习网

在各个浏览器中的效果mB9HTML5中文学习网 - HTML5先行者学习网

(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助