惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 【当耐特】
爱范儿
爱范儿
博客园 - 聂微东
美团技术团队
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG
罗磊的独立博客
V
Visual Studio Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

Hyde Blog

Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog
Hyde Blog
Hyde · 2025-10-05 · via Hyde Blog

卡片边框线条动画 ​

Html 部分 ​

html

<div class="animated-border-box"></div>

Css 部分 ​

详细信息

css

<style>
    /* 清除浏览器默认 */
    /* 清除所有元素内外边距 */
    *,
    *::before,
    *::after {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        /* 更直观的盒模型计算方式 */
    }

    /* 清除列表样式 */
    ul,
    ol {
        list-style: none;
    }

    /* 清除默认超链接样式 */
    a {
        text-decoration: none;
        color: inherit;
    }

    /* 清除表单元素默认样式 */
    input,
    button,
    textarea,
    select {
        font: inherit;
        /* 继承父元素字体 */
        background: transparent;
        border: none;
        outline: none;
        appearance: none;
        /* 清除浏览器默认外观 */
    }

    /* 清除图片底部间隙 */
    img {
        vertical-align: middle;
    }

    /* 清除表格边框合并 */
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }

    /* 清除文本级元素默认样式 */
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p {
        font-size: inherit;
        font-weight: normal;
    }

    /* 清除 HTML5 新增元素默认样式 */
    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    hgroup,
    menu,
    nav,
    section {
        display: block;
    }

    /* 清除按钮默认样式 */
    button {
        cursor: pointer;
        user-select: none;
    }

    /* 禁用文本区域缩放 */
    textarea {
        resize: none;
    }

    /* 清除媒体元素基线对齐 */
    audio,
    video {
        vertical-align: baseline;
    }

    .animated-border-box {
        width: 300px;
        height: 150px;
        position: relative;
        margin: 2rem;
        background: pink;
        border-radius: 6px;
    }

    /* 动态边框线 */
    .animated-border-box::before,
    .animated-border-box::after {
        content: '';
        position: absolute;
        width: 0;
        height: 0;
        transition: all 0.3s;
    }

    .animated-border-box::before {
        top: 0;
        left: 0;
        border-top: 2px solid transparent;
        border-left: 2px solid transparent;
    }

    .animated-border-box::after {
        bottom: 0;
        right: 0;
        border-bottom: 2px solid transparent;
        border-right: 2px solid transparent;
    }

    .animated-border-box:hover::before {
        width: 100%;
        height: 100%;
        border-top-color: #67cdcc;
        border-left-color: #7ec699;
        border-radius: 2px;
    }

    .animated-border-box:hover::after {
        width: 100%;
        height: 100%;
        border-bottom-color: #466eff;
        border-right-color: #cc99cd;
        border-radius: 2px;
        transition-delay: 0.2s;
    }
</style>

完整代码 ​

详细信息

html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    /* 清除浏览器默认 */
    /* 清除所有元素内外边距 */
    *,
    *::before,
    *::after {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      /* 更直观的盒模型计算方式 */
    }

    /* 清除列表样式 */
    ul,
    ol {
      list-style: none;
    }

    /* 清除默认超链接样式 */
    a {
      text-decoration: none;
      color: inherit;
    }

    /* 清除表单元素默认样式 */
    input,
    button,
    textarea,
    select {
      font: inherit;
      /* 继承父元素字体 */
      background: transparent;
      border: none;
      outline: none;
      appearance: none;
      /* 清除浏览器默认外观 */
    }

    /* 清除图片底部间隙 */
    img {
      vertical-align: middle;
    }

    /* 清除表格边框合并 */
    table {
      border-collapse: collapse;
      border-spacing: 0;
    }

    /* 清除文本级元素默认样式 */
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p {
      font-size: inherit;
      font-weight: normal;
    }

    /* 清除 HTML5 新增元素默认样式 */
    article,
    aside,
    details,
    figcaption,
    figure,
    footer,
    header,
    hgroup,
    menu,
    nav,
    section {
      display: block;
    }

    /* 清除按钮默认样式 */
    button {
      cursor: pointer;
      user-select: none;
    }

    /* 禁用文本区域缩放 */
    textarea {
      resize: none;
    }

    /* 清除媒体元素基线对齐 */
    audio,
    video {
      vertical-align: baseline;
    }

    .animated-border-box {
      width: 300px;
      height: 150px;
      position: relative;
      margin: 2rem;
      background: pink;
      border-radius: 6px;
    }

    /* 动态边框线 */
    .animated-border-box::before,
    .animated-border-box::after {
      content: "";
      position: absolute;
      width: 0;
      height: 0;
      transition: all 0.3s;
    }

    .animated-border-box::before {
      top: 0;
      left: 0;
      border-top: 2px solid transparent;
      border-left: 2px solid transparent;
    }

    .animated-border-box::after {
      bottom: 0;
      right: 0;
      border-bottom: 2px solid transparent;
      border-right: 2px solid transparent;
    }

    .animated-border-box:hover::before {
      width: 100%;
      height: 100%;
      border-top-color: #67cdcc;
      border-left-color: #7ec699;
      border-radius: 2px;
    }

    .animated-border-box:hover::after {
      width: 100%;
      height: 100%;
      border-bottom-color: #466eff;
      border-right-color: #cc99cd;
      border-radius: 2px;
      transition-delay: 0.2s;
    }
  </style>

  <body>
    <div class="animated-border-box"></div>
  </body>
</html>