You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用CSS为不规则形状添加渐变边框及伪元素标记?

实现带渐变边框的不规则形状+底部对勾标记

可以通过伪元素结合多层背景技巧实现这个效果,核心是让主体和底部突出部分的渐变边框保持一致,同时用伪元素绘制对勾。以下是完整实现代码:

完整代码

CSS 样式

.white-grad {
  position: relative;
  background: 
    linear-gradient(#ccc 0 0) padding-box,
    linear-gradient(to right, #9c20aa, #fb3570) border-box;
  color: #313149;
  padding: 10px;
  border: 5px solid transparent;
  border-radius: 15px;
  display: inline-block;
  margin: 75px 0;
}

/* 底部带渐变边框的突出容器 */
.white-grad::after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  background: 
    linear-gradient(#ccc 0 0) padding-box,
    linear-gradient(to right, #9c20aa, #fb3570) border-box;
  border: 5px solid transparent;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

/* 对勾标记 */
.white-grad::before {
  content: "✓";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  color: #fff;
  z-index: 1;
}

HTML 结构

<div class="white-grad"> Some text here</div>

<div class="white-grad"> Some long long long text here</div>

<div class="white-grad"> Some long long <br>long text here</div>

关键实现细节

  • 给.white-grad设置position: relative,确保伪元素能相对其定位
  • ::after伪元素复用了主体的渐变边框逻辑,通过border-top-left/right-radius和bottom定位,让它刚好衔接在主体底部,形成不规则的突出部分
  • ::before伪元素直接用字符✓作为对勾,通过z-index:1确保显示在最上层,避免被背景覆盖
  • 若需要调整突出部分的大小或形状,只需修改::after的width、height、border-radius和bottom值即可

内容的提问来源于stack exchange,提问作者kusiewicz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 11:13:12