css三角加文字的实现方法

1.不带圆角的效果和代码

  • 如何想要调整文字在这个三角里面的位置(高度方面的),可以调整文字所在标签样式 line-height的值

  • status标签和 txts标签的width和height属性值最好是相同的,如果你没写相同,效果会不一致,需要自己调整

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .fa {
        position: relative;
        width: 200px;
        height: 200px;
        border: 1px solid red;
      }
      .status {
        position: absolute;
        right: 0;
        top: 0;
        z-index: 2;
        overflow: hidden;
      }
      .icon {
        position: absolute;
        right: 0;
        top: 0;
        width: 110px;
        height: 110px;
        border: 8px;
        background: aqua;
        -webkit-clip-path: polygon(100% 0, 0 0, 100% 100%);
        clip-path: polygon(100% 0, 0 0, 100% 100%);
      }

      .txts {
        line-height: 60px;
        text-align: center;
        transform: rotate(45deg);
        transform-origin: center center;
        color: #ffffff;
        font-size: 18px;
      }
      .ce {
        width: 110px;
        height: 110px;
      }
    </style>
  </head>
  <body>
    <div class="fa">
      <div class="status ce">
        <div class="icon"></div>
        <div class="txts ce">三角文字</div>
      </div>
    </div>
  </body>
</html>

2.带圆角的代码,效果不是很好,如果有更好的实现方法请在评论区留言

  • 带圆角的话这个status 和 txts的宽度/宽度 是要比icon的宽度/高度小的,效果可以自己慢慢调

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .fa {
        position: relative;
        width: 200px;
        height: 200px;
        border: 1px solid red;
      }
      .status {
        position: absolute;
        right: 0;
        top: 0;
        z-index: 2;
        overflow: hidden;
        border-radius: 6px;
      }
      .icon {
        position: absolute;
        right: 0;
        top: 0;
        width: 110px;
        height: 110px;
        border: 8px;
        background: aqua;
        -webkit-clip-path: polygon(100% 0, 0 0, 100% 100%);
        clip-path: polygon(100% 0, 0 0, 100% 100%);
      }

      .txts {
        line-height: 60px;
        text-align: center;
        transform: rotate(45deg);
        transform-origin: center center;
        color: #ffffff;
        font-size: 18px;
      }
      /* 带圆角的话这个status 和 txts的宽度/宽度 是要比icon的宽度/高度小的,效果可以自己慢慢调 */
      .ce {
        width: 100px;
        height: 100px;
      }
    </style>
  </head>
  <body>
    <div class="fa">
      <div class="status ce">
        <div class="icon"></div>
        <div class="txts ce">三角文字</div>
      </div>
    </div>
  </body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是大刚啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值