效果1
源码展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:root {
--loading-grey: #ededed;
}
body {
background-color: #f6f6f6;
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
display: flex;
justify-content: space-evenly;
align-items: center;
min-height: 100hv;
}
.card {
width: 320px;
background-color: #fff;
border-radius: 6px;
overflow: hidden;
box-shadow: 0 4px 6px rgb(0, 0, 0, 0.12);
}
.image {
height: 200px;
}
.image img {
display: block;
width: 100%;
/* 规定应该从父元素继承 height 属性的值。 */
height: inherit;
/*
图片自适应属性
cover
被替换的内容在保持其宽高比的同时填充元素的整个内容框。
如果对象的宽高比与内容框不相匹配,该对象将被剪裁以适应内容框。
*/
object-fit: cover;
}
.content {
padding: 2rem 1.8rem;
}
h4 {
margin: 0 0 1rem;
font-size: 1.5rem;
line-height: 1.5rem;
}
.description {
font-size: 1rem;
line-height: 1.4rem;
}
/*骨架样式 */
.loading .image,
.loading h4,
.loading .description {
background-color: var(--loading-grey);
/* 白色光效 */
background: linear-gradient(100deg,
rgb(255, 255, 255, 0) 40%,
rgb(255, 255, 255, 0.5) 50%,
rgb(255, 255, 255, 0) 60%) var(--loading-grey);
background-size: 200% 100%;
background-position-x: 180%;
animation: 1s loading ease-in-out infinite;
}
@keyframes loading{
to {
background-position-x: -20%;
}
}
.loading h4 {
min-height: 1.6rem;
border-radius: 4px;
/* animation-delay: 0.5s; */
}
.loading .description {
min-height: 4rem;
border-radius: 4px;
/* animation-delay: 0.6s; */
}
</style>
</head>
<body>
<!--
实际使用的时候只要在加载的时候给容器加上loading这个 class
在数据加载完成后,将数据显示到指定位置 并将loading 移除就好了
-->
<div class="card">
<div class="image">
<img src="../css/img/1.jpg" alt="">
</div>
<div class="content">
<h4>标题</h4>
<div class="description">内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容
内容内容内容内容内容内容内容内容容内容
</div>
</div>
</div>
<div class="card loading">
<div class="image">
</div>
<div class="content">
<h4></h4>
<div class="description">
</div>
</div>
</div>
</body>
</html>
不定时更新补充