圆角边框是css3新增属性,在圆角边框呈现之前,前端开辟有的采用整块的圆角图片作为布景,有的采用小的圆角图片别离放在元素的四角,很是麻烦,矫捷性差,也达到降低了网站的整体机能,而圆角边的呈现则降低了开辟和维护的难度。
圆角边框(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;
}
html部门:
<div class="div1">圆角边框</div>
结果如图:
圆角边框也可以利用百分比作为单元,好比:将一个正方形的圆角边框设置为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部门:
<div class="box1">这是一个圆</div>
结果如图:
既然利用圆角边框可以绘制出一个圆,同样也可以绘制出一个椭圆。
例子:
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部门:
<div class="box2">这是一个椭圆</div>
结果如图:
设置分歧弧度的圆角
例子:
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部门:
<div id="box4">
<div class="div4">左上角为圆角</div>
<div class="div5">右上角为圆角</div>
<div class="div6">右下角为圆角</div>
<div class="div7">左下角为圆角</div>
</div>
结果如图:
注重,上面例子中,每句圆角边框代码都要零丁编写兼容代码。
兼容性代码要如许写:
.div4{
border-top-left-radius: 40px;
-moz-border-top-left-radius: 40px;
-webkit-border-top-left-radius: 40px;
}
如图,图顶用的是Chrome浏览器
今朝,ie9+撑持border-radius属性,Firefox、Chrome、Safari撑持所有新的边框属性
0 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!