html - 弹跳按钮
问题描述
我正在尝试创建一个具有弹跳效果的按钮,但不希望文本弹跳。我只想反弹红色容器和文本以保持静止。这是我尝试的。
button {
width: 240px;
color: var(--background-color-1);
cursor: pointer;
text-align: center;
text-transform: uppercase;
font-size: 16px;
position: absolute;
top: 19vw;
left: 50%;
background: red;
border: none;
backface-visibility: hidden;
padding: 16px 12px;
transition: all .3s;
filter: drop-shadow(0 0 15px yellow);
animation: bounce 1s infinite alternate;
}
@keyframes bounce {
to {
transform: scale(1.1);
filter: drop-shadow(0 0 0 yellow);
}
}
<button>Button Name</button>
解决方案
这是最好的简单方法。
button {
width: 240px;
color: var(--background-color-1);
cursor: pointer;
text-align: center;
text-transform: uppercase;
font-size: 16px;
position: absolute;
top: 19vw;
left: 50%;
border: none;
backface-visibility: hidden;
padding: 16px 12px;
z-index: 1;
}
button:before {
content: "";
width: 100%;
height: 100%;
display: block;
background-color: red;
transition: all .3s;
filter: drop-shadow(0 0 15px yellow);
animation: bounce 1s infinite alternate;
position: inherit;
top: 0;
left: 0;
z-index: -1;
}
@keyframes bounce {
to {
transform: scale(1.1);
filter: drop-shadow(0 0 0 yellow);
}
}
<button>Button Name</button>
推荐阅读
- java - Java继承:如何覆盖父类的实例变量/字段?
- jquery - 在 bxSlider 中将第一张卡片显示为第二张幻灯片的一半
- python - 从 py 转换为 exe 时出现错误
- kubernetes - Kubernetes 状态集控制器如何确定 Pod 是否处于就绪状态
- linux - 解释来自 /dev 文件的通信
- python - 刷新 Psutil 结果
- database - 在同一 REDCap 记录下创建新参与者;为记录生成附加标识符 ID
- javascript - 单击后使选项卡更改颜色
- flutter - 在颤振中如何清除栏中的通知?
- javascript - 没有得到 Radio input Javascript 的值