如何运用纯CSS 完成一个没有DOM元素的动画效果
发表时间:2025-10-29 来源:浏览器大全整理相关软件相关文章人气:
网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立在超文本基础之上的。超级文本标记语言之所以称为超文本标记语言,是因为文本中包含了所谓“超级链接”点。
本篇文章给大家带来的内容是关于如何使用纯CSS 实现一个没有DOM元素的动画效果,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
效果预览

代码解读
没有 dom 元素,直接写 css。
设置页面空间:
body {
position: fixed;
margin: 0;
width: 100vw;
height: 100vh;
}用伪元素设置背景图案:
body::before {
content: '';
position: fixed;
width: 200vmax;
height: 200vmax;
background-color: steelblue;
color: turquoise;
background-image:
linear-gradient(
45deg,
currentColor 25%,
transparent 25%, transparent 75%,
currentColor 75%),
linear-gradient(
45deg,
currentColor 25%,
transparent 25%, transparent 75%,
currentColor 75%);
background-position: 0 0, 5vmax 5vmax;
background-size: 10vmax 10vmax;平移背景图案:
body::before {
top: 50%;
left: 50%;
animation:
9s move infinite ease-in-out alternate;
}
@keyframes move {
from {
left: -40%;
top: -40%;
}
to {
left: -60%;
top: -60%;
}
}让背景图案转动起来:
body::before {
animation:
9s move infinite ease-in-out alternate,
9s -1.5s rotating infinite ease-in-out alternate;
}
@keyframes rotating {
to {
transform: rotate(180deg);
}
}平移页面:
body {
top: 50%;
left: 50%;
animation:
3s move infinite ease-in-out alternate;
}缩放页面:
body {
animation:
3s move infinite ease-in-out alternate,
3s zoom infinite ease-in-out alternate;
}
@keyframes zoom {
to {
transform: scale(10);
}
}最后,增加变色效果:
@keyframes rotating {
to {
transform: rotate(180deg);
filter: hue-rotate(1turn);
}
}大功告成!
相关推荐:
如何使用纯CSS实现一只移动的小白兔动画效果
如何使用纯CSS实现一个微笑打坐的小和尚
以上就是如何使用纯CSS 实现一个没有DOM元素的动画效果的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。