html - 是否可以为 CSS line-through text-decoration 设置动画?

标签 html css css-animations

我正在尝试使用 CSS 为一段文本上的一行设置动画,但它实际上并不是动画,只是从隐藏变为显示。谁能告诉我我正在尝试的是否真的可行?如果没有,还有另一种方法可以实现这一目标吗? HTML:

<div>
    The text in the span <span class="strike">is what I want to strike out</span>.
</div>

CSS:

@keyframes strike{
                from{text-decoration: none;}
                to{text-decoration: line-through;}
            }
 .strike{  
    -webkit-animation-name: strike; /* Chrome, Safari, Opera */
    -webkit-animation-duration: 4s; /* Chrome, Safari, Opera */
    animation-name: strike;
    animation-duration: 4s;
    animation-timing-function: linear;
    animation-iteration-count: 1;
    animation-fill-mode: forwards; 
    }

最佳答案

你可以像这样使用伪

请注意(感谢 Phlame ),如果要删除的行插入第二行,则此从左到右的动画将不起作用。为此,需要使用另一个伪元素和一些脚本来正确定位这两个元素。或者使用其他动画效果,例如就像 Oriol's answer 中建议的那样.

@keyframes strike{
  0%   { width : 0; }
  100% { width: 100%; }
}
.strike {
  position: relative;
}
.strike::after {
  content: ' ';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: black;
  animation-name: strike;
  animation-duration: 4s;
  animation-timing-function: linear;
  animation-iteration-count: 1;
  animation-fill-mode: forwards; 
}
<div>
    The text in the span <span class="strike">is what I want to strike out</span>.
</div>

关于html - 是否可以为 CSS line-through text-decoration 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267507/

相关文章:

html - Css Div left 100% 伸出父 div

css - CSS3 中带有过渡的延迟模糊过滤器

css - 使用 css 转换 :scale? 时如何删除闪烁线

javascript - 使用 preventDefault() 提交表单但保留浏览器自动完成功能

HTML 单选按钮 : add space between the buttons from the same groupe

html - 如何使音乐文件的 URL 在 iOS 上的 VLC 中播放?

javascript - 如何使用相对位置进行图像褪色?

html - 如何将div分配给文本

css - 等待图像加载后再显示

html - @keyframes 没有以预期的方式工作 CSS