本文摘自PHP中文网,作者V,侵删。
首先我们来看一下效果图:(视频教程推荐:css视频教程)
实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!DOCTYPE html>
< html >
< head >
< title ></ title >
< style type = "text/css" >
/* css3绘制三角形 */
.triangle{
width: 0px; /*设置宽高为0,所以div的内容为空,从才能形成三角形尖角*/
height: 0px;
border-bottom: 200px solid #00a3af;
border-left: 200px solid transparent; /*transparent 表示透明*/
border-right: 200px solid transparent;
}
</ style >
</ head >
< body >
< div class = "triangle" ></ div >
</ body >
</ html >
|
还是不理解的小伙伴可以看下面
1、设置div有一定宽高,四边设置边框
1 2 3 4 5 6 7 8 | .triangle{
width: 50px;
height: 50px;
border-top: 200px solid #00a497;
border-bottom: 200px solid #cc7eb1;
border-left: 200px solid #165e83;
border-right: 200px solid #c85179;
}
|
上面代码设置div有一定宽高,四边设置边框时,效果如下:
2、设置div宽高为0,四边设置边框宽度为200px
1 2 3 4 5 6 7 8 | .triangle{
width : 0px ;
height : 0px ;
border-top : 200px solid #00a497 ;
border-bottom : 200px solid #cc7eb1 ;
border-left : 200px solid #165e83 ;
border-right : 200px solid #c85179 ;
}
|
上面代码设置div宽高为0,四边边框设置不同颜色时,效果如下:
(相关教程推荐:CSS教程)
3、接下来div宽高仍为0,去掉border-top
1 2 3 4 5 6 7 | .triangle{
width : 0px ;
height : 0px ;
border-bottom : 200px solid #cc7eb1 ;
border-left : 200px solid #165e83 ;
border-right : 200px solid #c85179 ;
}
|
上面代码设置div宽高为0,只设置下边框和左右边框时,效果如下:
4、最后发现,只将border-bottom设置颜色,左右边框透明,既可得到三角形
1 2 3 4 5 6 7 | .triangle{
width : 0px ;
height : 0px ;
border-bottom : 200px solid #cc7eb1 ;
border-left : 200px solid transparent ;
border-right : 200px solid transparent ;
}
|
最终效果:
以上就是如何利用css画出一个三角形的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
原生js如何修改css
css比html更复杂为什么还要用?
html5 css 需不需要js
自学 html5 要多久
css如何设置背景图片灰度
css如何让文字居于div的底部
css如何去掉图片边框
css怎么取消颜色
css不让字体倾斜怎么实现
css实现分页条
更多相关阅读请进入《css》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 如何利用css画出一个三角形