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

相关推荐
GIS之路19 小时前
使用命令行工具 ogr2ogr 将 CSV 转换为 Shp 数据(二)
前端
嘉琪00119 小时前
Vue3+JS 高级前端面试题
开发语言·前端·javascript
vipbic20 小时前
用 Turborepo 打造 Strapi 插件开发的极速全栈体验
前端·javascript
天涯学馆20 小时前
为什么 JavaScript 可以单线程却能处理异步?
前端·javascript
Henry_Lau61720 小时前
主流IDE常用快捷键对照
前端·css·ide
陶甜也20 小时前
使用Blender进行现代建筑3D建模:前端开发者的跨界探索
前端·3d·blender
C+++Python20 小时前
CSS Grid和Flexbox有什么区别?
css
我命由我1234520 小时前
VSCode - Prettier 配置格式化的单行长度
开发语言·前端·ide·vscode·前端框架·编辑器·学习方法
HashTang21 小时前
【AI 编程实战】第 4 篇:一次完美 vs 五轮对话 - UnoCSS 配置的正确姿势
前端·uni-app·ai编程
JIngJaneIL21 小时前
基于java + vue校园快递物流管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js