代码之家  ›  专栏  ›  技术社区  ›  Kenyis

使用CSS设置边框动画

  •  2
  • Kenyis  · 技术社区  · 7 年前

    我想在我的计算机(本地)中重新创建CSS动画,但它不起作用,当我在Codepen中尝试代码时,它起作用了,我做错了什么?

    代码如下: https://codepen.io/jvera/pen/gXxgXx

    {
      background: none;
      border: 0;
      box-sizing: border-box;
      box-shadow: inset 0 0 0 2px #f45e61;
      color: #f45e61;
      font-size: inherit;
      font-weight: 700;
      margin: 1em;
      padding: 1em 2em;
      text-align: center;
      text-transform: capitalize;
      vertical-align: middle;
    }
    .draw {
      overflow: hidden;
      position: relative;
    }
    .draw::before, .draw::after {
      content: '';
      box-sizing: border-box;
      position: absolute;
      border: 2px solid transparent;
      width: 0;
      height: 0;
    }
    .draw::before {
      top: 0;
      left: 0;
      border-top-color: #60daaa;
      border-right-color: #60daaa;
      animation: border 2s infinite;
    }
    .draw::after {
      bottom: 0;
      right: 0;
      animation: border 2s 1s infinite, borderColor 2s 1s infinite;
    }
    
    @keyframes border {
      0% {
        width: 0;
        height: 0;
      }
      25% {
        width: 100%;
        height: 0;
      }
      50% {
        width: 100%;
        height: 100%;
      }
      100% {
        width: 100%;
        height: 100%;
      }
    }
    @keyframes borderColor {
      0% {
        border-bottom-color: #60daaa;
        border-left-color: #60daaa;
      }
      50% {
        border-bottom-color: #60daaa;
        border-left-color: #60daaa;
      }
      51% {
        border-bottom-color: transparent;
        border-left-color: transparent;
      }
      100% {
        border-bottom-color: transparent;
        border-left-color: transparent;
      }
    }
    <center><h2 class="draw">Titulo</h2><center>

    我创建了两个文件并将其放入文件夹中,当我运行HTML文件时,我看不到动画效果(如演示),那么,我该怎么办?为什么我没有看到结果?

    谢谢

    2 回复  |  直到 7 年前
        1
  •  2
  •   Puka James Goodwin    7 年前

    我不知道你的HTML&CSS技能,但可能你在样式表的链接方面做错了什么:

    <link rel="stylesheet" href="styles.css">
    
    1. 确保正确设置路径(参见本例: External CSS )为了以防万一,也许可以简单介绍一下HTML的基本知识?

    2. 此外,检查路径是相对路径还是绝对路径:

    • 指数html
    • /帮助/文章/如何设置网页。html

    绝对路径:

    请参阅 Full reference about the paths .

    希望我能帮上忙。

        2
  •  0
  •   GoofBall101    7 年前