设置css的border-color属性得到三角形或梯形

HTML(下面的效果图实现HTML的代码均一样)
<!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <title>JS Bin</title>
 </head>
 <body>
 <div id="wrapper"></div>
 </body>
 </html>
1、CSS(中间有width,有height)
 #wrapper{
 width:100px;
 height:100px;
 border-width: 100px;
 border-style: solid;
 border-color: blue black red yellow;
}
效果图
中间有width,有height
2、CSS(中间有width,无height)
#wrapper{
width:100px;
height:0;
border-width: 100px;
border-style: solid;
border-color: blue black red yellow;
}
效果图
中间有width,有无height
3、CSS(中间无width,有height)
#wrapper{
width:0;
height:100px;
border-width: 100px;
border-style: solid;
border-color: blue black red yellow;
}
效果图
中间无width,有height
4、CSS(中间无width,无height)
#wrapper{
width:0;
height:0;
border-width: 100px; 
border-style: solid;
border-color: blue black red yellow;
}
效果图
中间无width,无height

1、border-width:100px;设置元素边框上下左右宽度都是100px
2、border-color: blue black red yellow;设置元素四个边框的颜色
3、transparent : 颜色指定为透明的

利用上述出现情况和3个特点,那么我们就可以实现利用border-color属性获得不同角度的三角形和梯形。

5、CSS(中间无width,无height,三个边框颜色是transparent)
#wrapper{
width:0;
height:0px;
border-width: 100px;
border-style: solid;
border-color: transparent black   transparent transparent;
}
效果图
三角形实现
6、CSS(中间y有width,有height,三个边框颜色是transparent)
#wrapper{
width:100px;
height:100px;
border-width: 100px;
border-style: solid;
border-color:transparent transparent red transparent;
}
效果图
梯形图实现
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容