๋ฐ์ํ
์์ง์ด๋ ์ก๋ฉด์ฒด ์ ๋๋ฉ์ด์ ๐ฒ
์ด๋ฒ ํฌ์คํ ์์๋ ์์ง์ด๋ ์ก๋ฉด์ฒด ์ ๋๋ฉ์ด์ ์ ๋ง๋ค์ด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค!
HTML ์ฝ๋
cubeํด๋์ค๋ฅผ ๊ฐ์ง div ํ๊ทธ ์์ div ๋ฐ์ค๋ฅผ 6๊ฐ ๋ง๋ค๊ณ ์ฒซ๋ฒ์งธ div ๋ฐ์ค์ ๊ธ์๋ฅผ ๋ฃ์ต๋๋ค.
<div class="cube">
<div>์ฝ๋ฉ๊ณต์ฑ
</div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSS ์ฝ๋
body {
background-color: #999;
height: 100vh;
perspective: 1000px;
display: flex;
align-items: center;
justify-content: center;
}
.cube {
position: relative;
width: 100px; height: 100px;
transform-style: preserve-3d;
transform: rotatex(-20deg) rotatey(-140deg) translatez(0);
animation: rotate 8000ms linear infinite;
}
.cube div {
display:flex;
align-items: center;
justify-content: center;
position: absolute;
top: 0; left: 0;
width: 100px; height: 100px;
opacity: 0.75;
color: #fff;
}
.cube div:nth-child(1){
background: #ffcc80;
transform: rotatex(90deg) translatey(-100px);
transform-origin: center top;
animation: top 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(2){
background: #ffb74d;
transform-origin: center bottom;
transform: rotatex(-90deg) translatey(100px);
animation: bottom 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(3){
background: #ffa726;
transform-origin: left center;
transform: rotateY(-90deg) translateX(-100px);
animation: left 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(4){
background: #ff9800;
transform-origin: right center;
transform: rotateY(90deg) translateX(100px);
animation: right 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(5){
background: #fb8c00;
transform-origin: center center;
transform: rotateX(0deg);
animation: front 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(6){
background: #f57c00;
transform-origin: center center;
transform: rotateY(180deg) translatez(100px);
animation: back 4000ms ease-in-out 8000ms infinite;
}
@keyframes rotate {
0% {transform: rotatex(0) rotatey(0) rotatez(0) translatez(0) }
100% {transform: rotatex(360deg) rotatey(360deg) rotatez(360deg) translatez(0)}
}
@keyframes top {
0% {transform: rotatex(90deg) translatey(-100px) translatez(0);}
50% {transform: rotatex(90deg) translatey(-100px) translatez(100px);}
100% {transform: rotatex(90deg) translatey(-100px) translatez(0);}
}
@keyframes bottom {
0% {transform: rotatex(-90deg) translatey(100px) translatez(0);}
50% {transform: rotatex(-90deg) translatey(100px) translatez(100px);}
100% {transform: rotatex(-90deg) translatey(100px) translatez(0);}
}
@keyframes left {
0% {transform: rotateY(-90deg) translateX(-100px) scaleY(1);}
50% {transform: rotateY(-90deg) translateX(-100px) scaleY(3);}
100% {transform: rotateY(-90deg) translateX(-100px) scaleY(1);}
}
@keyframes right {
0% {transform: rotateY(90deg) translateX(100px) scaleY(1);}
50% {transform: rotateY(90deg) translateX(100px) scaleY(3);}
100% {transform: rotateY(90deg) translateX(100px) scaleY(1);}
}
@keyframes front {
0% {transform: rotateX(0deg) scaleY(1);}
50% {transform: rotateX(0deg) scaleY(3);}
100% {transform: rotateX(0deg) scaleY(1);}
}
@keyframes back {
0% {transform: rotateY(180deg) translatez(100px) scaleY(1);}
50% {transform: rotateY(180deg) translatez(100px) scaleY(3);}
100% {transform: rotateY(180deg) translatez(100px) scaleY(1);}
}
๊ฒฐ๊ณผ๋ฌผ
์ด๋ ๊ฒ ์ก๋ฉด์ฒด๊ฐ ๋์์์ด ํ์ ํ๋ฉด์ ์ธ๋ก๋ก ๋์ด๋ฌ๋ค ์ค์ด๋ฌ๋ค๋ฅผ ๋ฐ๋ณตํ๋ ์ ๋๋ฉ์ด์ ์ด ์์ฑ๋์์ต๋๋ค.
๋ฐ์ํ
'CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[CSS] ๋ง์ฐ์ค๋ฅผ ๋ฐ๋ผ๊ฐ๋ ๋์ ํจ๊ณผ ๋ง๋ค๊ธฐ๐ (9) | 2022.09.26 |
---|---|
[CSS] ๋ก๋ฉ ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ (6) | 2022.09.25 |
[CSS] ํตํต ํ๋ ๊ธ์ ํจ๊ณผ๐ฐ (8) | 2022.09.22 |
[CSS] ๋ง์ฐ์ค ์ค๋ฒ ํจ๊ณผ(Mouse Hover Effect) (4) | 2022.09.20 |
[CSS] SCSS๋ก ์จ์ด๋ธ ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ๐ (8) | 2022.09.19 |
๋๊ธ