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

相关推荐
SEO_juper24 分钟前
Node.js 全站 SEO 体检报告生成器:一次查完标题、描述、canonical、H1、图片
开发语言·前端·node.js·html·bash
NoteDeep 深度笔记1 小时前
DOM 被改乱了怎么办?Notedeep 编辑器的 normalize 设计
前端·javascript·编辑器
zhanlang02171 小时前
HTML 零基础入门到企业实战【第七章 7.2】form 标签属性:action、method、name、target 详解
前端·html
涛涛ing2 小时前
面试了20个前端,我发现高薪的都不怎么拼“底层原理”
前端
翼帆2 小时前
我用 AI 复刻了 CodeTank,重温代码坦克
前端·javascript·开源·ai编程·游戏开发·codetank
有趣的老凌2 小时前
学习MarkDown笔记
前端
掘金者阿豪3 小时前
数据库选型到底应该看什么?从业务需求到技术架构的实践分析
前端·后端
徐小夕4 小时前
万字拆解:零向量库、无模型微调,SAG2 凭什么刷新多跳问答 SOTA
前端·vue.js·github
黑土豆4 小时前
用 drawink 给业务页面加一层画板:从网页批注到无限板书
前端·javascript·github
恋猫de小郭5 小时前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter