效果演示
这个 HTML 和 CSS 代码创建了一个模拟加载效果的卡片,包含一个主加载条和两个辅助的加载条,用来模拟数据加载的过程。(骨架屏: 在需要等待加载内容的位置设置一个骨架屏,某些场景下比 Loading 的视觉效果更好。)
HTML
html
<div class="card">
<div class="card_load"></div>
<div class="card_load_extreme_title"></div>
<div class="card_load_extreme_descripion"></div>
</div>
- card:作为卡片的容器,包含三个子元素:card_load、card_load_extreme_title和card_load_extreme_descripion。
- card_load:代表主加载条,显示在卡片的最左侧。
- card_load_extreme_title和card_load_extreme_descripion:分别代表卡片标题和描述的加载条,显示在卡片的右侧。
CSS
css
.card {
width: 190px;
height: 90px;
background: #ffff;
box-shadow: 0 1px 25px rgba(0,0,0,0.2);
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
padding: 12px 10px;
border-radius: 5px;
}
.card_load {
width: 70px;
height: 70px;
position: relative;
float: left;
background: linear-gradient(120deg, #e5e5e5 30%, #f0f0f0 38%, #f0f0f0
40%, #e5e5e5 48%);
border-radius: 50%;
background-size: 200% 100%;
background-position: 100% 0;
animation: load89234 2s infinite;
}
.card_load_extreme_title {
width: 90px;
height: 10px;
position: relative;
float: right;
border-radius: 5px;
background: linear-gradient(120deg, #e5e5e5 30%, #f0f0f0 38%, #f0f0f0
40%, #e5e5e5 48%);
background-size: 200% 100%;
background-position: 100% 0;
animation: load89234 2s infinite;
}
.card_load_extreme_descripion {
width: 90px;
height: 47px;
position: relative;
float: right;
border-radius: 5px;
background: linear-gradient(120deg, #e5e5e5 30%, #f0f0f0 38%, #f0f0f0
40%, #e5e5e5 48%);
margin-top: 10px;
background-size: 200% 100%;
background-position: 100% 0;
animation: load89234 2s infinite;
}
@keyframes load89234 {
100% {
background-position: -100% 0;
}
}
- .card设置卡片的宽度、高度、背景色、阴影、位置、变换、内边距和边框半径。
- .card_load设置主加载条的宽度、高度、背景渐变、边框半径和背景大小。
- 使用background-position和animation属性创建水平移动的加载效果。
- .card_load_extreme_title 和 .card_load_extreme_descripion设置标题和描述加载条的宽度、高度、背景渐变、边框半径和背景大小。
- 同样使用background-position和animation属性创建加载效果。
- @keyframes load89234定义了一个关键帧动画,使背景位置从100%移动到-100%,实现加载条的动画效果。