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>
相关推荐
黄尚圈圈25 分钟前
Vue 中引入 ECharts 的详细步骤与示例
前端·vue.js·echarts
浮华似水1 小时前
简洁之道 - React Hook Form
前端
正小安3 小时前
如何在微信小程序中实现分包加载和预下载
前端·微信小程序·小程序
_.Switch5 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
一路向前的月光5 小时前
Vue2中的监听和计算属性的区别
前端·javascript·vue.js
长路 ㅤ   5 小时前
vite学习教程06、vite.config.js配置
前端·vite配置·端口设置·本地开发
长路 ㅤ   5 小时前
vue-live2d看板娘集成方案设计使用教程
前端·javascript·vue.js·live2d
Fan_web5 小时前
jQuery——事件委托
开发语言·前端·javascript·css·jquery
安冬的码畜日常5 小时前
【CSS in Depth 2 精译_044】第七章 响应式设计概述
前端·css·css3·html5·响应式设计·响应式
赛男丨木子丿小喵5 小时前
visual studio2022添加新项中没有html和css
css·html·visual studio