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>
相关推荐
勾勾圈圈蛋蛋6 分钟前
黑马Vue_day11:Vue3的watch,ref和reactive,vue2->vue3,defineOptions、Model
前端
AlloyTeamZy15 分钟前
我发现,一个人做小游戏最难的,根本不是写代码
前端·人工智能·程序员
触底反弹28 分钟前
🚀 20 行代码手写前端路由 + React Router 核心 API 一篇搞定!
前端·javascript·react.js
灏仟亿前端技术团队32 分钟前
企业级 Agent 中台建设方案
前端
程序员黑豆36 分钟前
鸿蒙应用开发:一次开发多端适配与自适应布局实战
前端·harmonyos
布兰妮甜1 小时前
Vue 状态管理选型:Pinia 完整实战,对比 Vuex,模块化持久化
前端·javascript·vue.js·pinia·vuex
神王宝宝 王者小学1 小时前
面向领域驱动架构的查询实现方式
前端·python·架构
小林ixn1 小时前
React Router 从入门到实战:一篇搞定路由配置、懒加载与嵌套路由
前端·react.js·前端框架
labixiong2 小时前
async/await 到底是不是 Generator 的语法糖?手写执行器,Babel 编译产物里藏着答案
前端·javascript·babel
windliang2 小时前
Claude Code 源码分析(六):上下文的发现、注入与压缩
前端·javascript·人工智能