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>
相关推荐
黄同学real11 分钟前
HTML5 新增的主要标签整理
前端·html·html5
liwulin050612 分钟前
【JAVAFX】实现屏幕指定区域截图,带尺寸显示
服务器·前端·python
沉迷...40 分钟前
tsconfig.json和tsconfig.node.json和tsconfig.app.json有什么区别
前端·vue.js·node.js
码上飞扬2 小时前
Nginx功能全解析:你的高性能Web服务器解决方案
服务器·前端·nginx
samuel9182 小时前
pinia实现数据持久化插件pinia-plugin-persist-uni
前端·vue
谢一歇_fn2 小时前
如何在uni-app中自定义输入框placeholder的样式
前端·javascript·uni-app
ganshenml2 小时前
【Web】如何解决 `npm run dev` 报错 `address already in use 127.0.0.1:9005` 的问题
前端
顽强d石头2 小时前
elementui里的el-tabs的内置样式修改失效?
前端·javascript·elementui
king199901023 小时前
小程序Npm package entry file not found?
前端·npm·node.js
程序猿阿伟3 小时前
《解锁CSS Flex布局:重塑现代网页布局的底层逻辑》
前端·css