【问题标题】:Why aren't my animation pseudo-elements working with an input element? [duplicate]为什么我的动画伪元素不能与输入元素一起使用? [复制]
【发布时间】:2020-04-03 20:07:02
【问题描述】:

我正在尝试模拟此处显示的按钮:https://codepen.io/nw/pen/udkIB

我正在尝试在值按钮中添加我的动画,但它不起作用。没有显示下载箭头形状和下载 nox 形状。

这是我的代码:

.buttonDownload {
  display: inline-block;
  border: none;
  position: relative;
  padding: 10px 25px;
  background-color: #4CC713;
  color: white;
  font-family: sans-serif;
  text-decoration: none;
  font-size: 0.9em;
  text-align: center;
  text-indent: 15px;
}

.buttonDownload:hover {
  background-color: #333;
  color: white;
}

.buttonDownload:before,
.buttonDownload:after {
  content: ' ';
  display: block;
  position: absolute;
  left: 15px;
  top: 52%;
}


/* Download box shape  */

.buttonDownload:before {
  width: 10px;
  height: 2px;
  border-style: solid;
  border-width: 0 2px 2px;
}


/* Download arrow shape */

.buttonDownload:after {
  width: 0;
  height: 0;
  margin-left: 3px;
  margin-top: -7px;
  border-style: solid;
  border-width: 4px 4px 0 4px;
  border-color: transparent;
  border-top-color: inherit;
  -webkit-animation: downloadArrow 2s linear infinite;
  animation: downloadArrow 2s linear infinite;
  -webkit-animation-play-state: paused;
  animation-play-state: paused;
}

.buttonDownload:hover:before {
  border-color: #4CC713;
}

.buttonDownload:hover:after {
  border-top-color: #4CC713;
  -webkit-animation-play-state: running;
  animation-play-state: running;
}


/* keyframes for the download icon anim */

@-webkit-keyframes downloadArrow {
  /* 0% and 0.001% keyframes used as a hackish way of having the button frozen on a nice looking frame by default */
  0% {
    margin-top: -7px;
    opacity: 1;
  }
  0.001% {
    margin-top: -15px;
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    margin-top: 0;
    opacity: 0;
  }
}

@keyframes downloadArrow {
  /* 0% and 0.001% keyframes used as a hackish way of having the button frozen on a nice looking frame by default */
  0% {
    margin-top: -7px;
    opacity: 1;
  }
  0.001% {
    margin-top: -15px;
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    margin-top: 0;
    opacity: 0;
  }
}
<form action="" method="POST">
  <div class="g-recaptcha" data-sitekey="your_site_key"></div>
  <br/>
  <input type="submit" value="Download" class="buttonDownload">
</form>

【问题讨论】:

  • 您的表单操作无效。绝对 action="" URI 必须以 https:// http://// 开头。
  • 为什么不直接使用您要模拟的 CodePen 中的工作代码?

标签: html css css-animations pseudo-element


【解决方案1】:

:before:after 等伪元素不适用于任何 &lt;input&gt; 元素。在您的链接示例中,它可以工作,因为它使用 &lt;a&gt;

所以你必须替换这个 HTML:

<input type="submit" value="Download" class="buttonDownload">

用这个:

<button type="submit" class="buttonDownload">Download</button>

演示:https://jsfiddle.net/fL2e6t8o/

【讨论】:

    猜你喜欢
    • 2011-11-15
    • 2015-08-31
    • 2017-04-27
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    相关资源
    最近更新 更多