栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

用css3实现三角(倒三角)形状图标

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用css3实现三角(倒三角)形状图标

废话不多说,直接上代码!



#box{width:100px; height:150px;margin:200px auto; background:#06F; position:relative}
#box:after{content:"";width:0px; height:150px; position:absolute; box-sizing:border-box;right:-30px;
border-top: 75px solid transparent;
border-left: 30px solid #06f;
border-bottom: 75px solid transparent;}
#box:before{content:"";width:0px; height:150px; position:absolute; box-sizing:border-box;left:-30px; background:#06f;
border-top: 75px solid transparent;
border-left: 30px solid #fff;
border-bottom: 75px solid transparent;}

表现形式:
解析:
重要属性:transparent(透明的)
文中css我们可以看出图标,左边(before)我们设置了top和bottom都设置了75像素的border宽;left设置了宽30px;
其实就等价于:一个宽高为30x150的长方形!

有人会问,为什么会出现切割状的形状,不应该是上面和下面形状都是长方形吗,因为我们这里上下都等于75px,而这里的border-left就相当于给它加的宽为30px;就相当于从(0,0)开始到(30,75)进行切割,所以,然后就实现了一个四分之一的三角图标;

下面我们给每一块都加上不同的颜色,大家来看看!



#box{width:100px; height:150px;margin:200px auto; background:#06F; position:relative}
#box:after{content:"";width:0px; height:150px; position:absolute; box-sizing:border-box;right:-30px;
border-top: 75px solid #0cf;
border-left: 30px solid #3FC;
border-bottom: 75px solid #f00;}
#box:before{content:"";width:0px; height:150px; position:absolute; box-sizing:border-box;left:-30px; background:#06f;
border-top: 75px solid #f00;
border-left: 30px solid #000;
border-bottom: 75px solid #0cf;}


现在看起来是不是明了很多了,其实还可以实现很多形状,这个得靠自己去计算各种角度!
这种的好处就是和SVG差不多,不管放大多少都不会出现图标模糊;可以自己写几个常用的保存下来,以后直接运用到自己的网页中,还可以支持透明度转换的!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/243316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号