SVG 渐变边框在 CSS 中的应用

SVG 渐变边框在 CSS 中的应用

javascript 复制代码
<template>
  <div class="home">
  
    <div class="one">
      <svg width="100%" height="100%">
        <rect x="2" y="2" width="100%" height="100%" fill="none"
          style="width: calc(100% - 4px);height: calc(100% - 4px);" rx="4" stroke="url(#paint0_linear_1_2)"
          stroke-width="4" stroke-linecap="round" />
        <defs>
          <linearGradient id="paint0_linear_1_2" x1="0" y1="0" x2="1" y2="0">
            <stop stop-color="#FFD75A" />
            <stop offset="1" stop-color="#ED424B" />
          </linearGradient>
        </defs>
      </svg>

    </div>

    <div class="one">

      <svg width="100%" height="100%" viewBox="0 0 100% 100%" fill="none" xmlns="http://www.w3.org/2000/svg">
        <rect x="0" y="0" width="100%" height="100%" rx="4" stroke="url(#paint0_linear_1_2)" stroke-linecap="round" />
        <defs>
          <linearGradient id="paint0_linear_1_2" x1="0" y1="0" x2="1" y2="0">
            <stop stop-color="#FFD75A" />
            <stop offset="1" stop-color="#ED424B" />
          </linearGradient>
        </defs>
      </svg>

    </div>

    <div class="one">

      <svg width="100%" height="100%" fill="none" xmlns="http://www.w3.org/2000/svg">
        <rect x="2" y="2" width="100%" height="100%" style="width: calc(100% - 4px);height: calc(100% - 4px);"
          stroke-width="2" rx="16" stroke-linecap="round" stroke="url(#paint0_linear_3269_5233)"
          stroke-dasharray="8 6" />
        <defs>
          <linearGradient id="paint0_linear_3269_5233" x1="0" y1="0" x2="100%" y2="100%" gradientUnits="userSpaceOnUse">
            <stop stop-color="#FFD75A" />
            <stop offset="1" stop-color="#ED424B" />
          </linearGradient>
        </defs>
      </svg>


    </div>

    <div class="one">

      <svg width="100%" height="100%" fill="none" xmlns="http://www.w3.org/2000/svg">

        <rect class="rect" x="2" y="2" width="100%" height="100%" stroke-width="2" rx="16" stroke-linecap="round"
          stroke="url(#paint0_linear_5234_3269)" stroke-dasharray="8 6" />
        <defs>
          <linearGradient id="paint0_linear_5234_3269" x1="0" y1="0" x2="100%" y2="100%" gradientUnits="userSpaceOnUse">
            <stop stop-color="#00bbff" />
            <stop offset="1" stop-color="red" />
          </linearGradient>
        </defs>
      </svg>


    </div>

  </div>
</template>

<script>

export default {
  name: 'HomeView',
  data() {
    return {
     
    }
  },
  
}
</script>

<style scoped>
.home {
  width: 100%;
  height: 100%;
}

.one {
  width: 100px;
  height: 80px;
  display: inline-block;
  margin: 0 10px;
}

.rect {
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  animation: move .3s infinite linear;
}

@keyframes move {
  0% {
    stroke-dashoffset: 0;
  }

  100% {
    stroke-dashoffset: 14;
  }
}
</style>
相关推荐
不爱说话郭德纲3 分钟前
👩‍💼产品姐一句小优化,让我给上百个列表加上一个动态实时计算高度的方法😿😿
前端·vue.js·性能优化
现在没有牛仔了6 分钟前
小试牛刀,用electron+vue3做了一个文件归纳程序~
前端·electron
FogLetter8 分钟前
Prisma + Next.js 全栈开发初体验:像操作对象一样玩转数据库
前端·后端·next.js
知识分享小能手8 分钟前
React学习教程,从入门到精通, React教程:构建你的第一个 React 应用(1)
前端·javascript·vue.js·学习·react.js·ajax·前端框架
李剑一9 分钟前
别乱封装,你看出事儿了吧...
前端·vue.js
文心快码BaiduComate13 分钟前
新增Zulu-CLI、企业版对话支持自定义模型、一键设置自动执行、复用相同终端,8月新能力速览!
前端·后端·程序员
walking95716 分钟前
JavaScript 神技巧!从 “堆代码” 到 “写优雅代码”,前端人必看
前端·面试
前端西瓜哥21 分钟前
图形编辑器开发:基于矩阵的画布缩放和移动实现
前端
walking95721 分钟前
前端 er 收藏!高性价比 JS 工具库,轻量又强大
前端·面试
gongzemin29 分钟前
Vue 项目权限管理 路由 按钮权限
前端·vue.js