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

如何用纯CSS实现带完整边框的clip-path切角效果?

实现带切角且保留对应边框的形状

clip-path会将元素的边框与内容一同裁切,因此要实现带切角的边框效果,需要将边框层和背景层分离处理,以下是两种可行方案:

方案1:嵌套元素实现

通过外层元素承载边框,内层元素承载背景和内容,两者应用相同的clip-path路径,确保切角形状一致。

HTML代码:

<div class="bottominfo">
  <div class="content"></div>
</div>

CSS代码:

.bottominfo {
  bottom: 1.9%;
  left: 5.7%;
  position: absolute;
  border: 1px solid #FF003C;
  clip-path: polygon(7% 0, 100% 0, 100% 30%, 100% 70%, 93% 100%, 30% 100%, 0 100%, 0% 30%);
  width: 50vw;
  height: 11vw;
}
.content {
  position: absolute;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 1px;
  background-color: rgba(204, 0, 2, 0.1);
  clip-path: polygon(7% 0, 100% 0, 100% 30%, 100% 70%, 93% 100%, 30% 100%, 0 100%, 0% 30%);
}

方案2:伪元素实现(无需额外HTML标签)

利用:before伪元素生成独立的边框层,原元素负责背景,两者应用相同的clip-path路径,通过定位让伪元素覆盖原元素下方,模拟边框效果。

HTML代码:

<div class="bottominfo"></div>

CSS代码:

.bottominfo {
  bottom: 1.9%;
  left: 5.7%;
  position: absolute;
  background-color: rgba(204, 0, 2, 0.1);
  clip-path: polygon(7% 0, 100% 0, 100% 30%, 100% 70%, 93% 100%, 30% 100%, 0 100%, 0% 30%);
  width: 50vw;
  height: 11vw;
}
.bottominfo::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  border: 1px solid #FF003C;
  clip-path: polygon(7% 0, 100% 0, 100% 30%, 100% 70%, 93% 100%, 30% 100%, 0 100%, 0% 30%);
  z-index: -1;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 16:55:30