纯CSS实现气泡框和内凹的圆角

气泡框

气泡框的小三角可以通过伪元素 ::before ::after 来实现:
html代码:

<div class="box">
    <div class="publickStyle back">filling</div>
    <div class="publickStyle emptyPub top">top</div>
    <div class="publickStyle emptyPub right">right</div>
    <div class="publickStyle emptyPub bottom">bottom</div>
    <div class="publickStyle emptyPub left">left</div>
  </div>

css部分:

 .box {
    width: 100%;
    height: 100%;
    padding-left: 50px;
  }
  .publickStyle {
    width: 200px;
    height: 50px;
    border-radius: 5px 5px;
    text-align: center;
    line-height: 50px;
    position: relative;
  }
  .back {
    background: skyblue;
    color: #fff;
  }
  .back::after {
    position: absolute;
    left: 100%;
    top: 50%;
    border: 5px solid transparent;
    border-left-color: skyblue;
    content: '';
    margin-top: -5px;
  }
  .emptyPub {
    width: 196px;
    border:2px solid skyblue;
    color: skyblue;
    margin-top: 20px;
  }
  .top::before {
    position: absolute;
    top: -18px;
    left: 50%;
    border: 8px solid transparent;
    border-bottom-color: skyblue;
    content: '';
    margin-left: -5px;
  }
  .top::after {
    position: absolute;
    top: -14px;
    left: 50%;
    border: 7px solid transparent;
    border-bottom-color: #fff;
    content: '';
    margin-left: -4px;
  }
  .right::before {
    position: absolute;
    left: 100%;
    top: 50%;
    border: 5px solid transparent;
    border-left-color: skyblue;
    margin: -5px 0 0 2px;
    content: '';
  }
  .right::after {
    position: absolute;
    left: 100%;
    top: 50%;
    border: 4px solid transparent;
    border-left-color: #fff;
    content: '';
    margin-top: -4px;
  }
  .bottom::before {
    position: absolute;
    left: 50%;
    top: 100%;
    border: 8px solid transparent;
    border-top-color: skyblue;
    margin-left: -4px;
    content: '';
  }
  .bottom::after {
    position: absolute;
    left: 50%;
    top: 100%;
    border: 5px solid transparent;
    border-top-color: #fff;
    margin-left: -1px;
    content: '';
  }
  .left::before {
    position: absolute;
    top: 50%;
    left: 0;
    border: 7px solid transparent;
    border-right-color: skyblue;
    content: '';
    margin-left: -16px;
    margin-top: -6px;
  }
  .left::after {
    position: absolute;
    top: 50%;
    left: 0;
    border: 6px solid transparent;
    border-right-color: #fff;
    content: '';
    margin-left: -12px;
    margin-top: -5px;
  }

image.png

内凹的圆角

我在刚开始工作的时候实现内凹的圆角一般用SVG来实现,虽然效果也不错,但是当时也是想过是否可以通过纯CSS来实现呢,后来看了很多大佬的文章,发现原来通过CSS来实现如此巧妙和有趣。正巧通过这个更文的活动记录一下。
主要通过radial-gradient实现,通过调整参数的比例来达到想要的效果。
html代码:

<div class="box">
    <div class="tab">
      <div class="yuanjiao yuanjiao_left"></div>
      <div class="tab1"></div>
      <div class="yuanjiao yuanjiao_right"></div>
    </div>
    <div class="bottom"></div>
  </div>

主要的css代码:

.box {
  width: 200px;
  height: 100px;
}
.tab {
  width: 80px;
  height: 20px;
  margin: 0 auto;
  display: flex;
}
.tab1 {
  width: 60px;
  height: 100%;
  background: skyblue;
  border-radius: 5px 5px 0 0;
}
.yuanjiao {
  width: 10px;
  height: 10px;
  background: skyblue;
  margin-top: 10px;
}
.yuanjiao_left {
  background: skyblue;
  background: radial-gradient(circle at -5% 0%, transparent 60%, transparent 75%, skyblue 35%);
}
.yuanjiao_right {
  background: radial-gradient(circle at 100% 10%, transparent 50%, transparent 75%, skyblue 35%);
}
.bottom {
  width: 100%;
  height: 30px;
  background: skyblue;
}

image.png
参考资料:
https://github.com/cssmagic/blog
https://codepen.io/JowayYoung/pen/GRZBKJd
https://cssarrowplease.com/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值