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

相关推荐
TE-茶叶蛋2 小时前
Vuerouter 的底层实现原理
开发语言·javascript·ecmascript
发呆小天才yy3 小时前
uniapp 微信小程序使用图表
前端·微信小程序·uni-app·echarts
@PHARAOH5 小时前
HOW - 在 Mac 上的 Chrome 浏览器中调试 Windows 场景下的前端页面
前端·chrome·macos
月月大王6 小时前
easyexcel导出动态写入标题和数据
java·服务器·前端
JC_You_Know7 小时前
多语言网站的 UX 陷阱与国际化实践陷阱清单
前端·ux
Python智慧行囊8 小时前
前端三大件---CSS
前端·css
Jinuss8 小时前
源码分析之Leaflet中Marker
前端·leaflet
成都渲染101云渲染66668 小时前
blender云渲染指南2025版
前端·javascript·网络·blender·maya
行走__Wz8 小时前
计算机学习路线与编程语言选择(信息差)
java·开发语言·javascript·学习·编程语言选择·计算机学习路线