效果预览:效果预览
源码下载:关注公众号【RMRF】,回复【css5】可获取源码
一、HTML
<!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>骨架屏</title>
<link rel="stylesheet" href="./css/index.css">
<style>
</style>
</head>
<body>
<div class="skeleton">
<div class="card">
<div class="img loading"></div>
<div class="title loading"></div>
<div class="text text-1 loading"></div>
<div class="text loading"></div>
<div class="text loading"></div>
</div>
</div>
</body>
</html>
二、CSS样式
* {
padding: 0px;
margin: 0px;
}
.skeleton {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.card {
position: relative;
padding: 30px;
width: 400px;
border-radius: 5px;
box-shadow: 0 0 6px #ddd;
}
.img {
height: 150px;
}
.title {
height: 40px;
width: 100%;
margin: 15px 0 20px;
}
.text {
height: 30px;
margin-top: 15px;
}
.text-1 {
margin-left: 40px;
}
.loading {
background: linear-gradient(90deg,
#f2f2f2 25%, #d1d1d1 40%, #f2f2f2 50%);
background-size: 400% 100%;
animation: loading 1.4s ease infinite;
}
@keyframes loading {
0% {
background-position: 100% 50%;
}
100% {
background-position: 0 50%;
}
}