border画三角形

1.直接添加三角形

<div class="triangleContainer">
    <div class="triangleContent">
        <div class="triangle"></div>
        <div class="title">想你呦</div>
    </div>
</div>

<style>
    body {
        background: #e5e5e5;
    }
    .triangleContainer {
        margin: 50px auto;
        width: 500px;
        height: 400px;
        background: #fff;
    }
    .triangleContent {
        position: relative;
    }
    .triangle {
        position: absolute;
        right: -70px;
        top: -70px;
        transform: rotate(45deg);
        /* 比较长的写法 */
        /*border-top: 70px solid transparent;*/
        /*border-bottom: 70px solid red;*/
        /*border-left: 70px solid transparent;*/
        /*border-right: 70px solid transparent;*/
        /* 简单写法 */
        border: 70px solid transparent;
        border-bottom-color: red;
    }
    .title {
        position: absolute;
        right: 8px;
        top: 17px;
        transform: rotate(45deg);
        font-size: 19px;
        color: #fff;
    }
</style>

效果图:

 

 2.使用伪类添加三角形(附带阴影效果)

添加两个伪类:一个伪类实现三角形,另一个用定位实现阴影效果

  •  这里使用微信小程序写的:
<view class="promptInfo">

  <text class="inviteMessage">邀请越多的好友,中奖几率越高哦!</text>

  <text class="clickMessage">我知道了</text>

</view>
.promptInfo{

  position: absolute;

  left: 5%;

  top: -28rpx;

  margin: 0 auto;

  padding: 20rpx 0;

  box-sizing: border-box;

  width: 88%;

  border-radius: 10rpx;

  z-index: 999;

  background: #fff;

  box-shadow: 3rpx 3rpx 3rpx rgba(0,0,0,.2);

  border: 0;

  font-size: 30rpx;

}

.promptInfo::before{

  position: absolute;

  bottom: -21rpx;

  right: 110rpx;

  z-index: 999;

  border-top: 20rpx solid rgba(0,0,0,.2);

  border-left: 20rpx solid transparent;

  border-right: 20rpx solid transparent;

  content: ""

}

.promptInfo::after{

  position: absolute;

  bottom: -17rpx;

  right: 110rpx;

  z-index: 999;

  border-top: 20rpx solid #fff;

  border-left: 20rpx solid transparent;

  border-right: 20rpx solid transparent;

  content: ""

}

.promptInfo .inviteMessage{

  padding-left: 30rpx;

}

.promptInfo .clickMessage {

  display: inline-block;

  margin-left: 15rpx;

  padding: 10rpx 20rpx;

  color: #fff;

  background: red;

  border-radius: 30rpx;

}

正在努力学习中,若对你的学习有帮助,留下你的印记呗(点个赞咯^_^)

往期好文推荐:

  1. webpack打包(二)(含面试)
  2. JavaScript面试基础
  3. http协议
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值