邪罗刹的菠萝阁


> 刚刚小邪我在试图设计一个灰常简洁的Discuz风格,然后突然想到要给主表格加圆角框。
> 接着就去搜索了很多的资料,那么现在在下面总结一下,也方便以后使用随时查阅。

> 这里的圆角框支持 IE Chrome Firefox Safari 等等,基本上所有的浏览器。
> 话说 IE 的圆角框灰常麻烦,是利用几个不用边角直接互相作用形成的,折磨开发者非常有效。

> P.s. 之前没说清楚,我这个是无图版的,有图的对IE来说就不会那么麻烦了,呵呵。

> 先拿 IE 的圆角框代码吓唬你们一下,挺住,勇士们:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>CSS制作圆角边框</title>
<style>
#main { margin:0 auto; text-align:center; width:650px; }
#xsnazzy h1, #xsnazzy h2, #xsnazzy p { margin:0 10px; letter-spacing:1px; }
#xsnazzy h1 { font-size:2.5em; color:#fff; }
#xsnazzy h2 { font-size:2em; color:#06a; border:0; }
#xsnazzy h3 { margin:0 10px; letter-spacing:1px; }
#xsnazzy p { padding-bottom:0.5em; }
#xsnazzy h2 { padding-top:0.5em; }
#xsnazzy { background:transparent; margin:1em; }
.xtop, .xbottom {	display:block; background:transparent; font-size:1px; }
.xb1, .xb2, .xb3, .xb4 { display:block; overflow:hidden;}
.xb1, .xb2, .xb3 { height:1px; }
.xb2, .xb3, .xb4 {
	background:#f9f9f9; border-left:1px solid #eee;
	border-right:1px solid #eee;
}
.xb1 { margin:0 5px; background:#eee;}
.xb2 { margin:0 3px; border-width:0 2px;}
.xb3 { margin:0 2px;}
.xb4 { height:2px; margin:0 1px;}
.xboxcontent {
	display:block; background:#f9f9f9; border:0 solid #eee;
	border-width:0 1px; color:#999;
}
.xboxcontent p { text-align:left; }

</style>
</head>
<body>
<div id="main">
	<div id="xsnazzy">
		<b class="xtop"> <b class="xb1"></b> <b class="xb2"></b>
		<b class="xb3"></b> <b class="xb4"></b>
	</b>
<div class="xboxcontent">
	<p></p><p></p>
	<h3>CSS制作圆角边框</h3>
	<p></p><p></p><p></p><p></p>
	<p>  > 你笑的时候,全世界都在笑;</p>
	<p>  > 你哭的时候,全世界只有你一个人在哭。</p>
	<p></p><p></p><p></p>
</div>
	<b class="xbottom">
	<b class="xb4"></b> <b class="xb3"></b>
	<b class="xb2"></b> <b class="xb1"></b>
</b>
</div>
</div>
</body>
</html>

> 嘎嘎,我太坏了。O(∩_∩)O,那现在放松一下。

1. Firefox对border-radius的支持

> -moz-border-radius: {1,4} | inherit
> -moz-border-radius-bottomleft : | inherit
> -moz-border-radius-bottomright : | inherit
> -moz-border-radius-topleft : | inherit
> -moz-border-radius-topright : | inherit

> 只对每个角设置一个半径,只支持实现四分之一圆角,并不支持椭圆形圆角。
> 具体每个角的命名规则也和W3C不一致,这个比较讨厌。
> Firefox3圆角已经相当圆滑了,Firefox2比较糟糕,好在它即将终结了。

2. Safari和Chrome对border-radius的支持

> -webkit-border-radius: {1,2} | inherit
> -webkit-border-bottom-left-radius : {1,2} | inherit
> -webkit-border-bottom-right-radius : {1,2} | inherit
> -webkit-border-top-left-radius : {1,2} | inherit
> -webkit-border-top-right-radius : {1,2} | inherit

> 每个属性有1个或2个值,当有两个值时1个表示水平半径。
> 一个表示垂直半径writing-mode改变也随之而变。所以,Safari和Chrome中的圆角可以是椭圆角。
> webkit的实现方法和 W3C的CSS3草案2005年版本 非常一致,
> 和当前的草案最大不同就是简写属性-webkit-border-radius的属性值也只有1个或2个值,意义和前面相同。
> Chrome中圆角锯齿比较严重,基本上和Firefox2是同一水平,或许是它的webkit版本较低造成的。
> 由于webkit出生于khtml,所以把 上面属性中的webkit换成khtml,
> 即会得到以khtml为核心的浏览器支持的属性了。
> 当相邻的角半径之和大于所在矩形区域的大小时,都会直接设置所有的角半径为0。
> 即圆角失效,而不会像Firefox那样同比率缩小。

3. Opera尚不支持border-radius

> (- -),Opera不支持,请使用上边的 IE 圆角框代码。

4. IE 的圆角框浏览图

Update:

5. Js+CSS 实现兼容IE和Firefox的圆角效果

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JS+CSS实现无图片圆角</title>
<style> body{background:#fff;} td{font-size:9pt} </style>
<script>
function setcorner(id,r,bo,bg)    {
switch(id){
case 1: x=parseInt("-"+r);xx=-1;y=parseInt("-"+r);yy=-1;break
case 2: x=parseInt("-"+r);xx=-1;y=1;yy=r;break
case 3: x=1;xx=r;y=parseInt("-"+r);yy=-1;break
case 4: x=1;xx=r;y=1;yy=r;break
}
corner_html="<div style=\"width:"+r+"px;height:"+r+"px;overflow:hidden\">"
for(i=x;i<=xx;i++)    {
for(ii=y;ii<=yy;ii++)    {
rr=i*i+ii*ii-r*r
if(rr<0){color=bg}else{color=""}
if(Math.abs(rr)<r){color=bo}
corner_html+=
"<div style=\"float:left;width:1px;height:1px;overflow:hidden;background:"
+color+"\"></div>"
}
}
corner_html+="</div>"
return(corner_html)
}
function corner()
{
corner_table=document.all.tags("table")
for(box_i=0;box_i<corner_table.length;box_i++)
{
if(corner_table[box_i].id=="box")
{corner_table[box_i].id="box_"+box_i}
}
for(corner_i=0;corner_i<corner_table.length;corner_i++) {
if(corner_table[corner_i].id=="corner"){
corner_table[corner_i].id="corner_"+corner_i
corner_id=document.getElementById(corner_table[corner_i].id)
style=eval(corner_id.className)
if(style.length==3){
switch(style[1]){
case "black": bo="#666666";bg="#999999";break
case "blue": bo="#0000ff";bg="#9999ff";break
case "red": bo="#FF3333";bg="#ff9999";break
case "green": bo="#009900";bg="#66cc33";break
case "yellow": bo="#cc9900";bg="#ff9966";break
case "pink": bo="#cc33cc";bg="#ff99ff";break
case "gray": bo="#eee";bg="#f9f9f9";break
}
bc=style[2]
}
else{bo=style[1];bg=style[2];bc=style[3]}
size=style[0]
corner_img="<img width=1px height=1px>"
corner_id.insertRow(0)
corner_id.insertRow(2)
corner_id.rows[0].insertCell(0)
corner_id.rows[0].insertCell(0)
corner_id.rows[0].insertCell(0)
corner_id.rows[1].insertCell(0)
corner_id.rows[1].insertCell(2)
corner_id.rows[2].insertCell(0)
corner_id.rows[2].insertCell(0)
corner_id.rows[2].insertCell(0)
corner_id.rows[0].cells[1].innerHTML=corner_img
corner_id.rows[1].cells[0].innerHTML=corner_img
corner_id.rows[1].cells[2].innerHTML=corner_img
corner_id.rows[2].cells[1].innerHTML=corner_img
corner_id.rows[0].cells[0].innerHTML=setcorner(1,size,bo,bg)
corner_id.rows[0].cells[2].innerHTML=setcorner(2,size,bo,bg)
corner_id.rows[2].cells[0].innerHTML=setcorner(3,size,bo,bg)
corner_id.rows[2].cells[2].innerHTML=setcorner(4,size,bo,bg)
corner_id.rows[1].cells[1].style.background=bc
corner_id.rows[0].cells[1].style.background=bg
corner_id.rows[1].cells[0].style.background=bg
corner_id.rows[1].cells[2].style.background=bg
corner_id.rows[2].cells[1].style.background=bg
corner_id.rows[0].cells[1].style.borderTop="1px solid "+bo
corner_id.rows[1].cells[0].style.borderLeft="1px solid "+bo
corner_id.rows[1].cells[2].style.borderRight="1px solid "+bo
corner_id.rows[2].cells[1].style.borderBottom="1px solid "+bo
box_id=eval("box_"+(corner_i+1))
box_style=eval(box_id.className)
if(box_style[0]==0){box_id.rows[0].style.display="none"}
box_id.rows[0].style.height="18px"
box_id.rows[0].style.fontWeight="bold"
box_id.rows[0].style.color="#999"
box_id.rows[0].style.background=bg
box_id.rows[1].style.background="#ffffff"
box_id.rows[1].cells[0].style.border=box_style[1]+"px solid "+bo
}
}
}
</script>
<head>
<body>
<table cellpadding=0 cellspacing=0 id=corner class="[4,'gray','']">
<tr><td>
<table cellpadding=2 cellspacing=0 id=box class="[1,1]" width=580 height=100>
<tr><td>Js+CSS 实现兼容IE和Firefox的圆角效果</td></tr>
<tr><td valign=top><Br>
 Js+CSS 实现兼容IE和Firefox的圆角效果:<Br>
 class="[4,'blue','#ffffff']": <Br>
 依次为:[圆角半径大小,颜色样式,背景]<Br>
 class="[1,1]":<Br>
 依次为:[是否显示标题,是否显示内容边框]<Br><Br>
</td></tr>
</table>
</td></tr></table>
<script>corner()</script>
</body>
</html>

Leave a comment
69 Comments.
  1. 第三眼 Mozilla Firefox Windows 坐沙发!#1

    ie真费劲 :exclaim:

    @
  2. 圆角有点麻烦,呵呵

    @
  3. exia Maxthon Windows 躺地板!#3

    圆角的边框就是要比那种单纯的有棱角的边框看着舒服一些~比较柔和

    @
  4. 九站 360浏览器 Windows 天花板!#4

    IE那个太有想法了,值得收藏下。
    -moz-border-radius和-webkit-border-radius我真是第一次知道,长了知识。
    这要写一个兼容的得写许多CSS码,还不如放一个圆角背影图呢,图片优化下和打上文本的大小也差不多了。

    @
  5. keon Mozilla Firefox Windows 下水道!#5

    呃~~看了下IE的~~大致明白了~~
    原来圆角是拼起来的~~辛苦~~

    @
    • @keon , 呵呵 ~ 无图版的代码 ~
      有图的比较简单 ~

      @
    • @keon , 饿 不是 ~
      比如有那种左边半个是圆角图片 ~
      然后中间是背景色 ~
      右边再是半个圆角图片 ~
      这样就可以自由横向伸缩 ~
      -------
      还有做4个圆角 ~ 放在Div的四个角上 ~
      然后背景色填充其他地方 ~
      这样就可以任意伸缩了 ~
      -------
      其实只要是可以根据内容自由伸缩的那种就算把 ~
      呵呵 ~

      @
  6. 这个倒是很强悍

    @
  7. 我看不懂啊看不懂。。不过支持小邪……

    @
  8. 制作好的怎么不截个图看看呢!

    @
  9. 我看不懂,还是扔了IE吧!

    @
    • @Awu , 哈哈 ~ KillIE ~ !
      话说我这个是无图版来着 有图就不用那么复杂鸟 ~
      谁叫我太闲了 嘎嘎 ~

      @
  10. 一点一点的定位?

    @
    • @漠岚,
      唔 有点难解释 ~
      不过可以说是一点一点地拼出一个圆角来 ~
      建议你把xb1到xb4几个删除 ~
      然后一个个逐步加进来 并查看效果 ~
      就可以慢慢理解了 呵呵 ~
      background:transparent - 制定元素默认背景颜色透明
      letter-spacing - 允许负值的文字间隔属性
      border-width - 可分别设置四条边的宽度

      @
  11. 圆角的话我记得有一个插件的,一个JS+CSS就可以了,记得之前用过

    @
  12. 不得不说,你已经是大侠了...

    @
  13. 是大侠,鉴定完毕!

    @
  14. 圆角实现起来简单,但要兼容每个浏览器确实不容易。方法很多但按自己需求用得恰当才是最好的。

    @
  15. 博主,乃一神人。

    @
  16. 偶也去试试。貌似有有趣~~~ :wink:

    @
  17. soulsolo.org不错的域名,适合做音乐

    @
  18. 我早不用IE6了

    @
  19. 这方法不错

    @
  20. 童鞋,俺留言收藏下。。做个记号。

    @
  21. 以前ie上一直很难加圆角呵呵

    @
  22. liying Mozilla Firefox Windows #23

    不是很明白啊~

    @
  23. liying Mozilla Firefox Windows #24

    谢谢你啊~
    我试着把主要的关键代码留了下来,尝试着又写了一下子 ,了解多了~

    非常感谢~ :smile:

    @
  24. mark一下。无图版很好,截图效果不错。再法克IE一下。

    @

Leave a Reply


[ Ctrl + Enter ]