css实现渐变色圆角边框,背景色自定义

大屏中常有渐变色圆角边框,图片会变形,直角边框可以直接使用border-image实现渐变色,圆角边框是不支持的,需要使用mask实现,结果如图:

实现代码如下:

javascript 复制代码
<template>
  <div class="screen-item-right">
    <div class="screen-item-right-content">
      <slot></slot>
    </div>
  </div>
</template>

<style style="scss" scoped>
.screen-item-right {
  position: relative;
  background: #ffffff00;
  padding: 5px;
  height: 100%;
  width: 100%;
  background: linear-gradient(270deg, rgba(14, 60, 74, 0.8) 20.45%, rgba(14, 60, 74, 0) 88.954%);
  border-radius: 6px;
  .screen-item-right-content {
    position: relative;
    height: 100%;
    width: 100%;
    padding: 10px;
    z-index: -1;
    &::after {
      --mask-bg: linear-gradient(red, red);
      --mask-clip: content-box, padding-box;
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: 6px;
      padding: 1px 1px 1px 0px;
      background: linear-gradient(270deg, #5cadbc99 20.45%, rgba(14, 60, 74, 0) 88.954%);
      mask-composite: exclude;
      mask-clip: var(--mask-clip);
      mask-image: var(--mask-bg), var(--mask-bg);
      -webkit-mask-image: var(--mask-bg), var(--mask-bg);
      -webkit-mask-clip: var(--mask-clip);
      -webkit-mask-composite: destination-out;
    }
  }
  &::after {
    --mask-bg: linear-gradient(red, red);
    --mask-clip: content-box, padding-box;
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    padding: 1px 1px 1px 0px;
    background: linear-gradient(270deg, #5cadbc 20.45%, rgba(14, 60, 74, 0) 88.954%);
    mask-composite: exclude;
    mask-clip: var(--mask-clip);
    mask-image: var(--mask-bg), var(--mask-bg);
    -webkit-mask-image: var(--mask-bg), var(--mask-bg);
    -webkit-mask-clip: var(--mask-clip);
    -webkit-mask-composite: destination-out;
  }
}
</style>

mask用法参考mask - CSS:层叠样式表 | MDN

相关推荐
zithern_juejin4 分钟前
Date/RegExp/Error/ArrayBuffer
javascript
zenRRan17 分钟前
Karpathy公开附议:AI Agent 的输出格式,正在从 Markdown 走向 HTML
前端·html
燐妤25 分钟前
前端HTML编程5:JavaScript完全指南
前端·javascript·html
八月欢喜29 分钟前
【Facebook】 实时消息监控难点解析
javascript·python·facebook
3D探路人33 分钟前
模灵 大模型聚合API 转发流程技术实现
java·大数据·开发语言·前端·人工智能·计算机视觉
烛阴1 小时前
Unity资源加载进化论:从AssetBundle到Addressables,一文带你吃透手游资源管理
前端·c#·unity3d
TO_WebNow1 小时前
使用thinkPHP8.x 访问接口提示跨域
前端·php
掘金一周1 小时前
回家的时候用车,不回家感觉又没啥用,这车还要不要买 | 沸点周刊 5.14
前端
zithern_juejin1 小时前
Map/Set/WeakMap/WeakSet
javascript
梦想的颜色1 小时前
前端UI宝藏SKILL——UI/UX Pro Max
前端·ui·ux