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

相关推荐
深蓝电商API7 分钟前
实战破解前端渲染:当 Requests 无法获取数据时(Selenium/Playwright 入门)
前端·python·selenium·playwright
bestcxx1 小时前
(二十七)、k8s 部署前端项目
前端·容器·kubernetes
鲸落落丶1 小时前
webpack学习
前端·学习·webpack
excel1 小时前
深入理解 3D 火焰着色器:从 Shadertoy 到 Three.js 的完整实现解析
前端
光影少年2 小时前
vue打包优化方案都有哪些?
前端·javascript·vue.js
硅谷工具人2 小时前
vue3边学边做系列(3)-路由缓存接口封装
前端·缓存·前端框架·vue
β添砖java4 小时前
CSS网格布局
前端·css·html
木易 士心5 小时前
Ref 和 Reactive 响应式原理剖析与代码实现
前端·javascript·vue.js
程序员博博5 小时前
概率与决策 - 模拟程序让你在选择中取胜
前端