border-radius : none | <length>{1,4} [/ <length>{1,4} ]?
说明
border-radius是一种缩写方法。如果“/”前后的值都存在,那么“/”前面的值设置其水平半径,“/”后面值设置其垂直半径。如果没有“/”,则水平和垂直半径相等。另外其四个值是按照top-left、top-right、bottom-right、bottom-left的顺序来设置的其主要会有下面几种情形出现:border-top-left-radius: <length> <length> //左上角 border-top-right-radius: <length> <length> //右上角 border-bottom-right-radius:<length> <length> //右下角 border-bottom-left-radius:<length> <length> //左下角
版本问题
-moz-border-radius-topleft: //左上角 -moz-border-radius-topright: //右上角 -moz-border-radius-bottomright: //右下角 -moz-border-radius-bottomleft: //左下角 等价于: -moz-border-radius: //简写
-webkit-border-top-left-radius: //左上角 -webkit-border-top-right-radius: //右上角 -webkit-border-bottom-right-radius: //右下角 -webkit-border-bottom-left-radius: // 左下角 等价于: -webkit-border-radius: //简写
border-top-left-radius: //左上角 border-top-right-radius: //右上角 border-bottom-right-radius: //右下角 border-bottom-left-radius: //左下角 等价于: border-radius: //简写
-moz-border-radius-topleft: <length> <length> //左上角 -moz-border-radius-topright: <length> <length> //右上角 -moz-border-radius-bottomright: <length> <length> //右下角 -moz-border-radius-bottomleft: <length> <length> //左下角 -webkit-border-top-left-radius: <length> <length> //左上角 -webkit-border-top-right-radius: <length> <length> //右上角 -webkit-border-bottom-right-radius: <length> <length> //右下角 -webkit-border-bottom-left-radius: <length> <length> // 左下角 border-top-left-radius: <length> <length> //左上角 border-top-right-radius: <length> <length> //右上角 border-bottom-right-radius: <length> <length> //右下角 border-bottom-left-radius: <length> <length> //左下角
几个示例来说事
HTML code
<div class="demo"></div>
.demo { border-radius: 10px; } 其等价于: .demo{ border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; }
demo { border-radius: 10px 20px; } 等价于: .demo { border-top-left-radius: 10px; border-bottom-right-radius: 10px; border-top-right-radius: 20px; border-bottom-left-radius: 20px; }
.demo { border-radius: 10px 20px 30px; } 等价于 .demo { border-top-left-radius: 10px; border-top-right-radius: 20px; border-bottom-left-radius: 20px; border-bottom-right-radius: 30px; }
.demo { border-radius:10px 20px 30px 40px; } 等价于 .demo { border-top-left-radius: 10px; border-top-right-radius: 20px; border-bottom-right-radius: 30px; border-bottom-left-radius: 40px; }
从上面四个实例中我们可以看出border-radius和border取值非常相似,我们border遵循TRBL原则(从上边右边下边左边分别对应1、2,3,4四个值),只不过border-radius换成了左上角(top-left)对就值1,右上角(top-right)对应值2,右下角(bottom-right)对应值3,左下角(bottom-left)对应值4.
注:如无特殊声明,本文实例所有基本代码格式如上所示,只在该元素上添加border-radius属性设置。
.demo { border-radius: 10px 15px 20px 30px / 20px 30px 10px 15px; }
这种写法我们前面有提到过,“/”前是指圆角的水平半径,而“/”后是指圆角的垂直半径,他们两都遵循TRBL的顺序原则。为了能让大家更清楚理解,我们把上面代码换成如下:
.demo { border-top-left-radius: 10px 20px; border-top-right-radius: 15px 30px; border-bottom-right-radius: 20px 10px; border-bottom-left-radius: 30px 15px; }
.demo {
border-radius: 10px / 20px;
}
等价于:
.demo {
border-top-left-radius: 10px 20px;
border-top-right-radius: 10px 20px;
border-bottom-right-radius: 10px 20px;
border-bottom-left-radius: 10px 20px;
}
border-radius: 水平1 水平2 / 垂直1 垂直2:
设置了两个水平值和两个垂直值,此时我们top-left和bottom-right具有相同的水平和垂直半径,也就是其中的水平1和垂直1;而top-right和bottom-left也具有相同的水平和垂直半径值,也就是水平2和垂直2,我们他拆分出来就是:
border-top-left-radius: 水平1 垂直1; border-bottom-right-radius: 水平1 垂直1; border-top-right-radius: 水平2 垂直2; border-bottom-left-radius: 水平2 垂直2;具体我们来看下面的实例:
.demo { border-radius: 10px 20px / 20px 10px; } 等价于: .demo { border-top-left-radius: 10px 20px; border-bottom-right-radius: 10px 20px; border-top-right-radius: 20px 10px; border-bottom-left-radius: 20px 10px; }
.demo { border-radius: 10px 20px 30px / 50px 60px; } 等价于: .demo { border-top-left-radius: 10px 50px; border-top-right-radius: 20px 60px; border-bottom-left-radius: 20px 60px; border-bottom-right-radius: 30px 50px; }
我们从上面等价代码中可以知道,不管他们怎么取值,“/”前后各自按TRBL顺序取值。那么到此,border-radius的一些用法就介绍完了。