css - 我正在尝试通过 CSS 从底部设置动画,但无法正常工作
问题描述
我试图通过css从底部出现一个跨度我编写了以下不起作用的代码,
span {
display: inline !important;
background-color: transparent !important;
overflow: hidden;
animation: from-btm 1s !important;
@keyframes from-btm {
from {
margin-bottom: -5%;
}
to {
margin-bottom: 0%;
}
}
}
解决方案
您的@keyframes
属性应该在 span 元素之外。它应该留在 span 元素之外,因为它是它自己的元素。像这样:
span {
display: inline !important;
background-color: transparent !important;
overflow: hidden;
animation: from-btn 1s ease 0s 1;
}
@keyframes from-btm {
from {
margin-bottom: -5%;
}
to {
margin-bottom: 0%;
}
}
此外,您的动画速记不是“正确编写的”,它应该animation: "animation-name" "animation-duration" "animation-display(ease, ease-in, ease-out, linear)" "animation-delay" animation-count(any number or even infinite);
如上所示。
同样出于性能原因,您应该考虑使用这样的transform
元素为位置设置动画:例如。
@keyframes from-btm {
from {
transform: translateY(200%);
}
to {
transform: translateY(10%);
}
}
此外,在使用变换时,请确保为您的元素添加一个位置属性span
,例如position: absolute
或position: relative
推荐阅读
- python - 最后一个有效项目的子集df - pandas
- email - 使用 imaplib 选择收件箱时,如何处理“文件夹中邮件过多”错误?
- graphql - 内容丰富的 graphql 从内容的媒体字段中获取指向图像的链接
- c# - 我不断收到错误消息,即我的 .NET 模型需要具有 0 args 或仅可选 args 的构造函数?
- javascript - 如何在 React 中访问和更新对象数组中的字段?
- ruby-on-rails - 来自 Github 的 gem rails 没有更新
- docker - 使用 fabric-samples 文件夹启动 Hyperledger Fabric 的测试网络时的端口冲突
- javascript - 通过点击事件监听器获取嵌套元素的属性值
- javascript - 使用正交相机时 GLTF 对象的纹理消失
- heroku - 在 Heroku 中使用 Ncat 进行代理身份验证