小编Moh*_*val的帖子

如何用动画改变元素CSS位置

我想将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)

html css user-interface

6
推荐指数
2
解决办法
8085
查看次数

标签 统计

css ×1

html ×1

user-interface ×1