我是靠谱客的博主 拉长白猫,这篇文章主要介绍css如何设置圆角,现在分享给大家,希望可以做个参考。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

方法1:

圆角边框(border-radius)的基本用法:

圆角边框的最基本用法就是设置四个相同弧度的圆角

复制代码
1
2
3
4
boder-top-left-radius:30px; //左上角 boder-top-right-radius:30px; //右上角 boder-bottom-left-radius:30px; //右下角 boder-bottom-right-radius:30px; //左下角
登录后复制

如果这四个弧度的圆角相同,可以写成:

复制代码
1
border-radius:30px;
登录后复制

例子:

css部分:

复制代码
1
2
3
4
5
6
7
8
9
10
.div1{ margin:0 auto; background: darkcyan; width:200px; height:200px; border:2px solid darkslategray; border-radius:30px; text-align: center; line-height: 200px; }
登录后复制

效果如图:

t01cf2c47792574a3e5.webp.jpg

方法2:

圆角边框也可以使用百分比作为单位,比如:将一个正方形的圆角边框设置为50%,那么就会形成一个圆,不过使用百分比与像素并不能等效。

注意:百分比大于50%后,形状就不会再变化了,圆角的半径不能超过宽/高的一半

例子:

css部分:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
.box1{ width:200px; height:200px; margin: 30px auto; border: 2px solid #e4007e; text-align: center; line-height: 200px; font-weight: bold; font-size: 24px; background: burlywood; border-radius: 50%;//圆角百分比 }
登录后复制

效果如图:

t012cd58fd3cf16512c.webp.jpg

方法3:

既然使用圆角边框可以绘制出一个圆,同样也可以绘制出一个椭圆。

例子:

css部分:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
.box2{ width:200px; height:300px; margin: 30px auto; border: 2px solid #e4007e; text-align: center; line-height: 200px; font-weight: bold; font-size: 24px; background: burlywood; border-radius: 100px/150px; }
登录后复制

效果如图:

t01180712640c6d58eb.webp.jpg

方法4:

设置不同弧度的圆角

例子:

css部分:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#box4{ width:500px; position: relative; margin:30px auto; } .div4,.div5,.div6,.div7{ width:200px; height:200px; text-align: center; color:seagreen; font-size: 26px; line-height: 200px; background: yellowgreen; border:2px solid darkslategray; float:left; margin:20px; } .div4{border-top-left-radius: 40px;} .div5{border-top-right-radius: 20px;} .div6{border-bottom-left-radius: 30px;} .div7{border-bottom-right-radius: 10px;}
登录后复制

效果如图:

t01063fc687197f7a4f.webp.jpg

注意事项

百分比大于50%后,形状就不会再变化了,圆角的半径不能超过宽/高的一半。

【推荐学习:css视频教程】

以上就是css如何设置圆角的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是拉长白猫最近收集整理的关于css如何设置圆角的全部内容,更多相关css如何设置圆角内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(97)

评论列表共有 0 条评论

立即
投稿
返回
顶部