css+图标偏移,CSS绘制不规则图标

最终效果图:

01740d7bb9e0

image.png

1、方法一:margin定位

CSS

/* 长方形 */

.a1{

background-color: rgb(91,155,236);

width: 150px;

height: 36px;

text-align: center;

}

/* 左下角直角三角形 */

.a2{

width: 0;

height: 0;

margin-top: -6px;

border-top: 24px solid rgb(0, 112, 192);

border-left: 33px solid transparent;

}

/* 右边上三角 */

.a3{

width: 0;

height: 0;

margin-left: 150px;

margin-top: -60px;

border-top: 18px solid rgb(91, 155, 236);

border-right: 20px solid transparent;

}

/* 右边下三角 */

.a4{

width: 0;

height: 0;

margin-left: 150px;

margin-top: 2px;

border-bottom: 16px solid rgb(91, 155, 236);

border-right: 20px solid transparent;

}

HTML

标题文字

2、方法二:float定位

同行元素用float定位要好一些,不然用margin定位会出现不同浏览器因为识别px的大小不同而出现偏移。就像上面margin定位的在IE浏览器中会出现右边两个三角形向上偏移,不能同行。接下来用浮动定位优化一下。

CSS

/* 长方形 */

.a1{

background-color: rgb(91,155,236);

float: left;

clear: right;

width: 150px;

height: 36px;

text-align: center;

}

/* 右边上三角 */

.a3{

width: 0;

height: 0;

float: left;

border-top: 18px solid rgb(91, 155, 236);

border-right: 20px solid transparent;

}

/* 右边下三角 */

.a4{

width: 0;

height: 0;

border-bottom: 18px solid rgb(91, 155, 236);

border-right: 20px solid transparent;

}

/* 左下角直角三角形 */

.a2{

width: 0;

height: 0;

float: left;

clear: left;

border-top: 24px solid rgb(0, 112, 192);

border-left: 33px solid transparent;

}

h4{

margin-top:4px;

}

HTML

标题文字

小结:主要思想是分割特殊图形,用基本图形拼接。后面再归纳一篇基础图形绘制的文章。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值