clip-path画图形

clip-path可截取不规则图形
clip-path

<div
	class="panel-container"
	style="width: 300px;height: 300px;margin: 50px auto;">
</div>

通过加背景色,先画外圈,再画内圈,实现只留有边框长度的样式

<style lang="scss" scoped>
$--cornerGap: 16px; /* 角落空隙长度,(宽高的长度 不是斜边的长度) */
$--border: 1px; /* 边框 */
.panel-container {
  position: relative;
  margin: 16px;
  padding: 16px;
}
.panel-container::before{
  content: "";
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #3972b0;

  clip-path: polygon(
    0 0,
    calc(100% - $--cornerGap) 0,
    100% $--cornerGap,
    100% calc(100% - $--cornerGap),
    calc(100% - $--cornerGap) 100%,
    $--cornerGap 100%,
    0 calc(100% - $--cornerGap),
    0 0,

    $--border 0,
    $--border calc(100% - $--cornerGap),
    $--cornerGap calc(100% - $--border),
    calc(100% - $--cornerGap) calc(100% - $--border),
    calc(100% - $--border) calc(100% - $--cornerGap),
    calc(100% - $--border) $--cornerGap,
    calc(100% - $--cornerGap) $--border,
    $--border $--border,
  );
}
</style>

更加复杂的边框

更加复杂的clip-path

$--cornerGap: 16px; /* 角落空隙长度(宽高的长度,不是斜边的长度) */
$--border: 1px; /* 边框 */
$--concaveLength: 88px; /* 凹陷长度,外侧长度,且不包含gap */
$--concaveBottomLength: 148px; /* 底部凹陷长度,外侧长度,且不包含gap */
$--slopeWidth: 8px; /* 凹陷斜角长度(宽高的长度,不是斜边的长度) */
$--gap: 2px; /* 凹陷内容和边框线的距离 */
.panel-container {
  position: relative;
  margin: 16px;
  padding: 16px;
}
.panel-container::before{
  content: "";
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #3972b0;

  clip-path: polygon(
    0 0,
    calc(100% - $--cornerGap) 0,
    100% $--cornerGap,
    100% calc(50% - $--concaveLength/2 - $--gap),
    calc(100% - $--slopeWidth) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc(100% - $--slopeWidth) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    100% calc(50% + $--concaveLength/2 + $--gap),
    100% calc(100% - $--cornerGap),
    calc(100% - $--cornerGap) 100%,
    calc(50% + $--concaveBottomLength/2 + $--gap) 100%,
    calc(50% + $--concaveBottomLength/2 + $--gap - $--slopeWidth) calc(100% - $--slopeWidth),
    calc(50% - $--concaveBottomLength/2 - $--gap + $--slopeWidth) calc(100% - $--slopeWidth),
    calc(50% - $--concaveBottomLength/2 - $--gap) 100%,
    $--cornerGap 100%,
    0 calc(100% - $--cornerGap),
    0 calc(50% + $--concaveLength/2 + $--gap),
    $--slopeWidth calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    $--slopeWidth calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    0 calc(50% - $--concaveLength/2 - $--gap),
    0 0,

    $--border 0,
    $--border calc(50% - $--concaveLength/2 - $--gap),
    calc($--slopeWidth + $--border) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc($--slopeWidth + $--border) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    $--border calc(50% + $--concaveLength/2 + $--gap),
    $--border calc(100% - $--cornerGap),
    $--cornerGap calc(100% - $--border),
    calc(50% - $--concaveBottomLength/2 - $--gap) calc(100% - $--border),
    calc(50% - $--concaveBottomLength/2 - $--gap + $--slopeWidth) calc(100% - $--slopeWidth - $--border),
    calc(50% + $--concaveBottomLength/2 + $--gap - $--slopeWidth) calc(100% - $--slopeWidth - $--border),
    calc(50% + $--concaveBottomLength/2 + $--gap) calc(100% - $--border),
    calc(100% - $--cornerGap) calc(100% - $--border),
    calc(100% - $--border) calc(100% - $--cornerGap),
    calc(100% - $--border) calc(50% + $--concaveLength/2 + $--gap),
    calc(100% - $--slopeWidth - $--border) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    calc(100% - $--slopeWidth - $--border) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc(100% - $--border) calc(50% - $--concaveLength/2 - $--gap),
    calc(100% - $--border) $--cornerGap,
    calc(100% - $--cornerGap) $--border,
    $--border $--border,
  );
}

每条边框上加装饰 background-image可同时添加多个图片

边框上加装饰

<style lang="scss">
$--cornerGap: 16px; /* 角落空隙长度(宽高的长度,不是斜边的长度) */
$--border: 1px; /* 边框 */
$--concaveLength: 88px; /* 凹陷长度,外侧长度,且不包含gap */
$--concaveBottomLength: 148px; /* 底部凹陷长度,外侧长度,且不包含gap */
$--slopeWidth: 6px; /* 凹陷斜角长度(宽高的长度,不是斜边的长度) */
$--gap: 4px; /* 凹陷内容和边框线的距离 */
.panel-container {
  position: relative;
  margin: 16px;
  padding: 16px;
}
.panel-container::before {
  position: absolute;
  top: 0;
  left: 0;
  content: "";
  width: 100%;
  height: 100%;
  background-image:
    url("../assets/images/adornborder-left.png"),
    url("../assets/images/adornborder-bottom.png"),
    url("../assets/images/adornborder-right.png");
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-position: left center, bottom center, right center;
}
.panel-container::after{
  content: "";
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #3972b0;

  clip-path: polygon(
    0 0,
    calc(100% - $--cornerGap) 0,
    100% $--cornerGap,
    100% calc(50% - $--concaveLength/2 - $--gap),
    calc(100% - $--slopeWidth) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc(100% - $--slopeWidth) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    100% calc(50% + $--concaveLength/2 + $--gap),
    100% calc(100% - $--cornerGap),
    calc(100% - $--cornerGap) 100%,
    calc(50% + $--concaveBottomLength/2 + $--gap) 100%,
    calc(50% + $--concaveBottomLength/2 + $--gap - $--slopeWidth) calc(100% - $--slopeWidth),
    calc(50% - $--concaveBottomLength/2 - $--gap + $--slopeWidth) calc(100% - $--slopeWidth),
    calc(50% - $--concaveBottomLength/2 - $--gap) 100%,
    $--cornerGap 100%,
    0 calc(100% - $--cornerGap),
    0 calc(50% + $--concaveLength/2 + $--gap),
    $--slopeWidth calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    $--slopeWidth calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    0 calc(50% - $--concaveLength/2 - $--gap),
    0 0,

    $--border 0,
    $--border calc(50% - $--concaveLength/2 - $--gap),
    calc($--slopeWidth + $--border) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc($--slopeWidth + $--border) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    $--border calc(50% + $--concaveLength/2 + $--gap),
    $--border calc(100% - $--cornerGap),
    $--cornerGap calc(100% - $--border),
    calc(50% - $--concaveBottomLength/2 - $--gap) calc(100% - $--border),
    calc(50% - $--concaveBottomLength/2 - $--gap + $--slopeWidth) calc(100% - $--slopeWidth - $--border),
    calc(50% + $--concaveBottomLength/2 + $--gap - $--slopeWidth) calc(100% - $--slopeWidth - $--border),
    calc(50% + $--concaveBottomLength/2 + $--gap) calc(100% - $--border),
    calc(100% - $--cornerGap) calc(100% - $--border),
    calc(100% - $--border) calc(100% - $--cornerGap),
    calc(100% - $--border) calc(50% + $--concaveLength/2 + $--gap),
    calc(100% - $--slopeWidth - $--border) calc(50% + $--concaveLength/2 + $--gap - $--slopeWidth),
    calc(100% - $--slopeWidth - $--border) calc(50% - $--concaveLength/2 - $--gap + $--slopeWidth),
    calc(100% - $--border) calc(50% - $--concaveLength/2 - $--gap),
    calc(100% - $--border) $--cornerGap,
    calc(100% - $--cornerGap) $--border,
    $--border $--border,
  );
}
</style>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值