1.实现方式
网页中常见一些三角形,使用 CSS 直接画出来就可以,不必做成图片或者字体图标。
一张图, 你就知道 CSS 三角是怎么来的了, 做法如下:
我们只需要把容器宽高设为0,边框设宽一点,然后三面边框的背景颜色为透明即可。具体代码如下:
.triangle {
width: 0;
height: 0;
line-height: 0;
font-size: 0;
border: 50px solid transparent;
border-left-color: pink;
}
效果如下图
2.例子
京东商城的三角号
<!--index.wxml-->
<view class="container">
<!-- <button type="primary" bindtap="CountChange">+1</button> -->
<view class="dialog">
<view class="triangle"></view>
</view>
</view>
/**index.wxss**/
.dialog {
width: 200px;
height: 249px;
position: relative;
background-color: rgb(4, 238, 109);
}
.triangle {
width: 0;
height: 0;
position: absolute;
right: 20px;
top: -32px;
line-height: 0;
font-size: 0;
border: 16px solid transparent;
border-bottom-color: tomato;
}