【前端html+css】纯css实现带小三角的方形对话框样式

最终样式如下:

首先编写div

<div class="aasd " style="text-align: left;padding-left: 15px;">
    <span >
      aaaaaaaaa</span>
  </div>

其次边框定义

   .aasd {
      position: relative;
      border: 2px solid pink;
      margin: 20px auto;
      width: 246px;
      height: 83px;
      line-height: 43px;
      color: white;
      text-align: center;
      border-radius: 10px;
      font-family: sans-serif;
    }

 接下来就是实现三角形

主要是用border-color可以吧一个方形分成上下左右四个三角形

barder-colortransparent是继承父类颜色

所以我们只用这样

    .aasd:before {
      content: '';
      width: 0;
      height: 0;
      border: 20px solid;
      position: absolute;
      top: 83px;
      right: 150px;
      border-color: pink transparent transparent;
    }

如果要实现中间挖空可以写一个after覆盖一点原来的before

   .aasd:after {
      content: '';
      width: 0;
      height: 0;
      border: 20px solid;
      position: absolute;
      top: 80px;
      right: 150px;
      border-color: white transparent transparent;
    }

 全部代码

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Test</title>
  <style>
    .aasd {
      position: relative;
      border: 2px solid pink;
      margin: 20px auto;
      width: 246px;
      height: 83px;
      line-height: 43px;
      color: white;
      text-align: center;
      border-radius: 10px;
      font-family: sans-serif;
    }

    .aasd:before {
      content: '';
      width: 0;
      height: 0;
      border: 20px solid;
      position: absolute;
      top: 83px;
      right: 150px;
      border-color: pink transparent transparent;
    }


    .aasd:after {
      content: '';
      width: 0;
      height: 0;
      border: 20px solid;
      position: absolute;
      top: 80px;
      right: 150px;
      border-color: white transparent transparent;
    }
    .aasd span{
      font-size: 18px;
      color: #aaaa7f;
    }
  
  </style>
</head>

<body>

  <div class="aasd " style="text-align: left;padding-left: 15px;">
    <span >
      aaaaaaaaa</span>
  </div>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值