gpt4 book ai didi

html - 如何在媒体查询中定义关键帧?

转载 作者:行者123 更新时间:2023-11-28 03:07:48 25 4
gpt4 key购买 nike

在 800 像素以上的显示器上一切正常,但在 800 像素或以下时它无法按预期工作。

我的HTML和CSS如下:

.my_test{
width:50px;
height: 50px;
background:red;
display: inline-block;
-webkit-animation: aaa 0.5s infinite;
-o-animation: aaa 0.5s infinite;
animation: aaa 0.5s infinite;

position: relative;
}


@-webkit-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@-o-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@-moz-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@keyframes aaa {
from { left:0px; }
to { left:50px; }
}

@media screen (max-width: 800px) {

@-webkit-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@-o-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@-moz-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@keyframes aaa {
from { top:0px; }
to { top:50px; }
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/_test.css">
</head>
<body>
<div class="my_test" id="my_test">

</div>

</body>
</html>

我是否在媒体查询中错误地使用了关键帧?

最佳答案

您只是缺少媒体查询中的 :

@media screen and (max-width: 800px)

这是工作。当您运行代码片段时,您可以在预览 Pane 中看到,它按照媒体查询中定义的关键帧的指示上下动画。要在宽度超过 800px 时查看它的工作情况,请单击“全屏”。

.my_test{
width:50px;
height: 50px;
background:red;
display: inline-block;
-webkit-animation: aaa 0.5s infinite;
-o-animation: aaa 0.5s infinite;
animation: aaa 0.5s infinite;
position: relative;
}

@-webkit-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@-o-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@-moz-keyframes aaa {
from { left:0px; }
to { left:50px; }
}
@keyframes aaa {
from { left:0px; }
to { left:50px; }
}

@media screen and (max-width: 800px) {

@-webkit-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@-o-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@-moz-keyframes aaa {
from { top:0px; }
to { top:50px; }
}
@keyframes aaa {
from { top:0px; }
to { top:50px; }
}
}
<div class="my_test"></div>

关于html - 如何在媒体查询中定义关键帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31802748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com