圆角边框

css3实现圆角边框
方法/步骤1:
圆角边框(border-radius)的基本用法:

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

boder-top-left-radius:30px; //左上角

boder-top-right-radius:30px; //右上角

boder-bottom-left-radius:30px; //右下角

boder-bottom-right-radius:30px; //左下角

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

border-radius:30px;

例子:

css部分:

.div1{

margin:0 auto;

background: darkcyan;

width:200px;

height:200px;

border:2px solid darkslategray;

border-radius:30px;

text-align: center;

line-height: 200px;

}
在这里插入图片描述

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

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

例子:

css部分:

.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%;//圆角百分比

}

html部分:

这是一个圆
:

在这里插入图片描述

方法/步骤3:
既然使用圆角边框可以绘制出一个圆,同样也可以绘制出一个椭圆。

例子:

css部分:

.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;

}

html部分:

这是一个椭圆

在这里插入图片描述

方法/步骤4:
设置不同弧度的圆角

例子:

css部分:

#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;}

HTML部分:

左上角为圆角
右上角为圆角
右下角为圆角
左下角为圆角
在这里插入图片描述

方法/步骤5:
注意,上面例子中,每句圆角边框代码都要单独编写兼容代码。

兼容性代码要这样写:

.div4{

border-top-left-radius: 40px;

-moz-border-top-left-radius: 40px;

-webkit-border-top-left-radius: 40px;

}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值