세상에서 가장 간단한 Skeleton UI With Only HTML & CSS
오늘은 회사에서 백엔드 개발자분의 요청으로 Skeleton UI를 가장 간단하게 만들어달라는 요청이 있어서 최대한 빨리 만들어 보았습니다.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
.wrapper {
width: 20rem;
border: 1px solid #e4eaef;
border-radius: 12px;
overflow: hidden;
}
@keyframes loading {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
.imgBox {
height: 207px;
background: #f7f9fa;
background-size: 200% 100%;
animation: loading 2.5s infinite;
}
.infoBox {
padding: 12px;
> :nth-child(1) {
width: 100%;
height: 1.5rem;
border-radius: 0.5rem;
background-color: #e4eaef;
background-size: 200% 100%;
animation: loading 2.5s infinite;
}
> :nth-child(2) {
margin-top: 1rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.itemBox {
display: flex;
gap: 0.5rem;
}
.lastItemBox {
display: flex;
justify-content: space-between;
align-items: center;
}
.itemIcon {
width: 1rem;
height: 1rem;
border-radius: 0.1rem;
background-color: #e4eaef;
background-size: 200% 100%;
animation: loading 2.5s infinite;
}
.itemMent {
width: 5rem;
height: 1rem;
border-radius: 0.5rem;
background-color: #e4eaef;
background-size: 200% 100%;
animation: loading 2.5s infinite;
}
.priceBox {
width: 6rem;
height: 1.8rem;
border-radius: 0.5rem;
background: #e4eaef;
border-radius: 1rem;
background-size: 200% 100%;
animation: loading 2.5s infinite;
}
}
</style>
<body>
<div class="wrapper">
<div class="imgBox"></div>
<div class="infoBox">
<div></div>
<div>
<div class="itemBox">
<div class="itemIcon"></div>
<div class="itemMent"></div>
</div>
<div class="itemBox">
<div class="itemIcon"></div>
<div class="itemMent"></div>
</div>
<div class="itemBox">
<div class="itemIcon"></div>
<div class="itemMent"></div>
</div>
<div class="lastItemBox">
<div class="itemBox">
<div class="itemIcon"></div>
<div class="itemMent"></div>
</div>
<div class="priceBox"></div>
</div>
</div>
</div>
</div>
</body>
</html>여기서 핵심은 @keyframes에서 opacity를 이용하여 구현한 것입니다.

코드를 그대로 가져다가 실행하시면 opcity가 변함으로 인해 반짝거리는 효과를 보실 수 있습니다.
- #opacity를 활용
- #가장 쉬운
- #스켈레톤 UI