<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.a{
width: 400px;
height: 300px;
background-color: black;
}
.b {
width: 400px;
height: 300px;
position: relative;
z-index: 1;
color: #fff;
}
.b::after {
content: "";
background: url("https://scpic.chinaz.net/files/pic/pic9/202203/apic38894.jpg");
background-size: 100%;
opacity: 1;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
animation: vanishIn 2s;
}
@keyframes vanishIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<div class="a">
<div class="b">
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
</div>
</div>
</body>
</html>
纯css仅背景图片从透明到显示动画,并且可设置其他底色
于 2022-03-08 16:44:23 首次发布