纯CSS实现花括号 ‘{‘ (一)

先展示最终效果

在这里插入图片描述

前言

今天群内有人说像这样的花括号怎么实现在这里插入图片描述
我就用微信截图给他简单画了一下实现思路,如下图:
在这里插入图片描述
过了一会他用另一个思路也实现了,如下图:
在这里插入图片描述
就是放大文本嘛,不好看,不好看
我就决定自己写一个

version 1

通过好几个矩形实现的,很复杂还不好看,不好看
在这里插入图片描述

最终版本

注:可使用动态样式 来调整花括号的宽高
在这里插入图片描述

代码如下:

<style>
    * {
      padding: 0;
      margin: 0;
    }

    .box {
      padding: 100px;
      width: 100px;
      height: 200px;
    }
      /* border: 1px solid #956e6e; */

    .TTT{
      height: 15px;
    }
    .base{
      height: 100px;
      width: 30px;
      position: relative;
      box-sizing: border-box;
    }
    .t{
      background-color: antiquewhite;
      border-bottom-right-radius: 30px;
      border: 1px solid #000;
      border-top: none;
      border-left: none;
      &:before{
        content: '';
        height: 30px;
        width: 30px;
        background-color: rgb(248, 165, 57);
        position: absolute;
        right: -31px;
        top: -30px;
        border: 1px solid #000;
        border-top-left-radius: 100%;
        border-right:none;
        border-bottom:none;
      }
    }
    .b{
      margin-top: -1px;
      background-color: rgb(220, 196, 164);
      border-top-right-radius: 30px;
      border: 1px solid #000;
      border-bottom: none;
      border-left: none;
      &:before{
        content: '';
        height: 30px;
        width: 30px;
        background-color: rgb(248, 165, 57);
        position: absolute;
        right: -31px;
        bottom: -30px;
        border: 1px solid #000;
        border-bottom-left-radius: 100%;
        border-top: none;
        border-right: none;
      }
    }
  </style>
</head>

<body>

  <div class="box">
    <div class="base t">
    </div>
    <div class="base b">
    </div>
  </div>

</body>

最后:喜欢的同学,记得点赞关注哦!

兄弟们 有后续 :
纯CSS实现花括号 ‘{‘ (二)(自适应内容高度) https://blog.csdn.net/weixin_45856516/article/details/137347812

  • 45
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个CSS实现一片渐变叶子的例子: HTML代码: ```html <div class="leaf"></div> ``` CSS代码: ```css .leaf { width: 0; height: 0; border-top: 50px solid transparent; border-bottom: 50px solid transparent; border-right: 100px solid #5cb85c; background: linear-gradient(to bottom, #5cb85c 0%, #4cae4c 100%); position: relative; transform: rotate(45deg); } .leaf:before { content: ""; position: absolute; top: -25px; left: -25px; width: 0; height: 0; border-top: 50px solid transparent; border-bottom: 50px solid transparent; border-right: 100px solid #5cb85c; transform: rotate(-45deg); } .leaf:after { content: ""; position: absolute; top: -25px; left: 25px; width: 0; height: 0; border-top: 50px solid transparent; border-bottom: 50px solid transparent; border-left: 100px solid #4cae4c; transform: rotate(45deg); } ``` 解释: 这个例子中,我们使用了三个伪元素来实现一片叶子的效果。其中,主要的叶子元素是一个长方形,通过`border`属性来定义了其形状。我们使用了`linear-gradient`属性来实现渐变效果,从上到下从浅绿色渐变到深绿色。通过`transform`属性的`rotate`函数,我们将叶子旋转了45度。 接下来,我们使用了两个伪元素,分别在叶子的左上角和右上角创建了两个三角形,用于填补叶子的两个角落。这两个三角形也是通过`border`属性来定义的,同样使用`transform: rotate()`函数来旋转至正确的位置。 最终的效果如下图所示: ![渐变叶子效果](https://cdn.jsdelivr.net/gh/0xAiKang/CDN/pictures/gradient-leaf.png)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值