๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ : 3D ๋ฐ•์Šค ์• ๋‹ˆ๋ฉ”์ด์…˜

by ์ฝ”ํŒŒ์นด 2022. 9. 22.
728x90

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ : 3D ๋ฐ•์Šค ์• ๋‹ˆ๋ฉ”์ด์…˜

์˜ค๋Š˜์€ ์›€์ง์ด๋ฉด์„œ ํฌ๊ธฐ๊ฐ€ ๋ณ€ํ˜•๋˜๋Š” 3D ๋ฐ•์Šค๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ž‘์—…ํ•ด๋ณผ ์• ๋‹ˆ๋ฉ”์ด์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

See the Pen Untitled by mj0614k (@mj0614k) on CodePen.


1. HTML ์†Œ์Šค

<div class="cube">
    <div>์†Œ๋ฆ„</div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

cube class๋ฅผ ๊ฐ€์ง„ div ๋ฐ•์Šค๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ฃผ๊ณ , ๊ทธ ์•ˆ์— div ๋ฐ•์Šค 6๊ฐœ๋ฅผ ์ž‘์—…ํ•ด ์ค๋‹ˆ๋‹ค. div ๋ฐ•์Šค 6๊ฐœ๋Š” ์ •์œก๋ฉด์ฒด์˜ ๊ฐ๊ฐ์˜ ๋ฉด์ž…๋‹ˆ๋‹ค. ์›ํ•˜๋Š” ๋ฌธ๊ตฌ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

2. CSS ์†Œ์Šค

body {
    background-color: lavender;
    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-color: #ffcc80;
    transform-origin: center top;
    transform: rotatex(90deg) translatey(-100px);
    animation: top 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(2) {
    background-color: #ffb74d;
    transform-origin: center bottom;
    transform: rotatex(-90deg) translatey(100px);
    animation: bottom 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(3) {
    background-color: #ffa726;
    transform-origin: left center;
    transform: rotatey(-90deg) translatex(-100px);
    animation: left 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(4) {
    background-color: #ff9800;
    transform-origin: right center;
    transform: rotatey(90deg) translatex(100px);
    animation: right 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(5) {
    background-color: #fb8c00;
    transform-origin: center center;
    transform: rotatex(0deg);
    animation: front 4000ms ease-in-out 8000ms infinite;
}
.cube div:nth-child(6) {
    background-color: #ffb74d;
    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 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 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 front {
    0% {transform: rotatex(0deg) scaley(1)}
    50% {transform: rotatex(0deg) scaley(3)}
    100% {transform: rotatex(0deg) scaley(1)}
}
@keyframes back {
    0% {transform: rotatex(180deg) translatez(100px) scaley(1)}
    50% {transform: rotatex(180deg) translatez(100px) scaley(3)}
    100% {transform: rotatex(180deg) translatez(100px) scaley(1)}
}

์ €๋Š” ์ด๊ฒƒ์„ ์ดํ•ดํ•  ๋งŒํผ ์•„์ง ์„ฑ์žฅํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค... ์„ค๋ช…๋„ ๋ชป ํ•ด...

์•„๋ฌดํŠผ ์œ„์˜ HTML, CSS ์†Œ์Šค๋ฅผ ํ•ฉ์น˜๋ฉด ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์™„์„ฑ๋ฉ๋‹ˆ๋‹ค.

728x90

๋Œ“๊ธ€

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๐Ÿฆ™

CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘