我想将HTML元素位置从静态更改为固定在前50%并保留50%的浏览器窗口,但代码只会导致背景颜色变化!
div {
width: 100px;
height: 100px;
background-color: red;
position: static;
top: auto;
left: auto;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
from {
background-color: red;
position: static;
top: auto;
left: auto;
}
to {
background-color: yellow;
position: fixed;
top: 50%;
left: 50%;
}
}
Run Code Online (Sandbox Code Playgroud)