<body>
<div id="box"></div>
</body>```
<style>
#box{
width: 200px;
height: 200px;
background-color: green;
margin: 40px auto;
border: 2px solid black;
border-radius:50%;
}
</style>
执行结果:
![border-radius:50%](http:https://img.haomeiwen.com/i4021100/387bc7bd760de305.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
``border-radius:20px;``执行结果:
![border-radius:20px](http:https://img.haomeiwen.com/i4021100/892b8c58b7435eb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这个20px其实就是一个半径为20px的圆,每个角上都是一个圆。
下面加入辅助线,就能很清晰的理解了。
![border-radius:20px](http:https://img.haomeiwen.com/i4021100/8c36d6e2844c0d1d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
测试以下代码:
``border-radius:20px 40px;``
``border-radius:20px 100px 50px;``
``border-radius:20px 100px 50px 10px;``
``border-radius:20px 100px / 50px 10px;``
``border-radius:20px 100px 40px 10px/ 50px 30px 70px 10px;``
结果:
![border-radius:20px 40px](http:https://img.haomeiwen.com/i4021100/78567f1bbd1e35a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![border-radius:20px 100px 50px](http:https://img.haomeiwen.com/i4021100/5f45b8cc1b96d8a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![border-radius:20px 100px 50px 10px](http:https://img.haomeiwen.com/i4021100/b620e5899f4bc50b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![border-radius:20px 100px / 50px 10px](http:https://img.haomeiwen.com/i4021100/da22e9dec92d9d88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![border-radius:20px 100px 40px 10px/ 50px 30px 70px 10px](http:https://img.haomeiwen.com/i4021100/339eb23cd80419c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
结论:
``border-radius:20px; //四个角半径``
``border-radius:20px 40px; //左上&右下 半径 右上&左下 半径``
``border-radius:20px 100px 50px; //左上 半径 右上&左下 半径 右下 半径``
``border-radius:20px 100px 50px 10px; //左上 右上 右下 左下 半径``
``border-radius:20px 100px / 50px 10px; // X轴 / Y轴``
``border-radius:20px 100px 40px 10px/ 50px 30px 70px 10px; // X轴 / Y轴``
>IE 9、Safari 5、Chrome 4和Firefox 4,都支持上述的border-radius属性;
早期版本的Safari和Chrome,支持-webkit-border-radius属性;
早期版本的Firefox支持-moz-border-radius属性;
为了保证兼容性,只需同时设置-webkit-border-radius和border-radius即可。
border-top-left-radius:20px;
border-top-right-radius:20px;
border-bottom-left-radius:20px;
border-bottom-right-radius:20px;
>以上是标准语法,同样可以实现效果。
注:top left bottom right 位置不能互换!
网友评论