这是我的web page美元.

获取问题后,当AJAX请求进行时,将对update按钮应用css类‘updating’.

该类有两个伪元素.(:之前n:之后)

但仅当添加类时:之前出现而不是:after (它也有内容属性)

.update-question-form button {
display: inline-block;
    background-color: #007bff;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 16px;
position: relative;
  overflow: hidden;
  z-index: 1;
}


/* Add animation to the update button */

.update-question-form button.updating:before,
.update-question-form button.updating::after {
  
  position: absolute;
  width: 33%;
  height: 200%;
  transform: translateX(-50%) translateY(-50%) rotate(-20deg);
  animation: slide1 1s linear infinite;
  z-index: -1;
}

.update-question-form button.updating::after {
content: " ";
background-color: #ccc;
  animation: slide2 1s linear infinite;
}

.update-question-form button.updating:before {
content: '';
background-color: #09316c;
  animation: slide1 1s linear infinite;
}

@keyframes slide1 {
  0% {
    right: -33%;
  }
  100% {
    right: 100%;
  }
}

@keyframes slide2 {
  0% {
    right: -100%;
  }
  100% {
    right: 33%;
  }
}

推荐答案

正如您在这里看到的那样,它工作得很好:

@keyframes slide1 {
  0% {
    right: -33%;
  }
  100% {
    right: 100%;
  }
}

@keyframes slide2 {
  0% {
    right: -100%;
  }
  100% {
    right: 33%;
  }
}

.button {
  display: inline-block;
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 16px;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.button.updating::before,
.button.updating::after {  
  position: absolute;
  width: 33%;
  height: 200%;
  transform: translateX(-50%) translateY(-50%) rotate(-20deg);
  animation: slide1 1s linear infinite;
  z-index: -1;
}

.button.updating:before {
  content: '';
  background-color: yellow;
  animation: slide1 1s linear infinite;
}

.button.updating::after {
  content: '';
  background-color: red;
  animation: slide2 1s linear infinite;
}
<button class="button updating">Click me!</button>

但是,在您的站点中,还有一些其他样式正在将display: none应用到您的::after伪元素:

button::after,
input[type=button]::after,
input[type=reset]::after,
input[type=submit]::after,
.button::after,
.wc-block-grid__products .wc-block-grid__product .wp-block-button__link::after,
.added_to_cart::after {
    display: none;
}

您可以在DevTools>;Elements>;Styles中看到它,一直滚动到底部:

enter image description here

您有几种方法可以修复它:

  • 更改上面的 Select 器,使它们更具体,而不是将display: none;应用于所有::after个伪元素.

  • .button.updating::after上加上display: blockdisplay: inline-block,因为这个 Select 器已经比上面的 Select 器更具体了.

  • 如果上面的属性不起作用(如果display属性仍然被上面的display: none覆盖),您可以在它的基础上添加!important,即使我会鼓励您不要使用它/滥用它(这通常是一种代码气味).

Html相关问答推荐

springBoot + Thymeleaf:属性中的UTF-8

Blazor中有1像素高行的表格

如何在一个div中心字体图标?

如何在元素的三条边中间换行边框?

为什么在移动视图中,这个水平可滚动的表格会在表格的右侧显示额外的空间?

我应该怎么做才能显示出整个字符串?

Style=背景图像URL引用变成&;Quot;

如何在R rmarkdown中创建循环中的分页表?

如何在VB.NET中用打印预览和直接打印的方式在Html中打印数据表的内容,包括页眉/设置纸张/方向/适合页面/总计

try 更新我的Node.js应用程序中的用户,但我收到错误.然而,当我使用postman 时,更新工作正常

如何使用css在响应图像后面添加形状?

一旦大于最大限制,JQuery 取消 Select 复选框

在Angular中,类型"HTMLDivElement"不能分配给类型"Node"

视频添加到 Html 与 Github 不同步

如何使我的设计适合与我的框架尺寸不同的视口?

如何让一个 div 元素粘在另一个元素上?

需要禁用聚焦输入的工具提示(jquery)

在 html 邮箱的左侧和右侧制作多个元素很热门吗?

涉及短代码时如何在页面上定位元素?

如何在没有 JS 的情况下创建带搜索的 Select 菜单