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

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ : ๊ณต ํŠ€๊ธฐ๊ธฐ

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

CSS ์• ๋‹ˆ๋ฉ”์ด์…˜ : ๊ณต ํŠ€๊ธฐ๊ธฐ

์˜ค๋Š˜์€ CSS์˜ ๋‹ค์–‘ํ•œ ์†์„ฑ์„ ์ด์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ž‘์—…ํ•ด๋ณผ ์• ๋‹ˆ๋ฉ”์ด์…˜์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์กฐ๋žญ์ด๋–ก ๊ฐ™๋„ค์š”.

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


1. HTML ์†Œ์Šค

<div class="wrapper">
    <div></div>
</div>
<div class="wrapper">
    <div></div>
</div>
<div class="wrapper">
    <div></div>
</div>
<div class="wrapper">
    <div></div>
</div>
<div class="wrapper">
    <div></div>
</div>

์ž”์ƒ์„ ํฌํ•จํ•˜์—ฌ ๋‹ค์„ฏ ๊ฐœ์˜ ๊ณต์„ ๋งŒ๋“ค ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ๋‹ค์„ฏ ๊ฐœ์˜ wrapper ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ง„ div ๋ฐ•์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

2. CSS ์†Œ์Šค

* {
    box-sizing: border-box;
}
body {
    background: linear-gradient(to top, pink 0%, skyblue 100%);
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}
.wrapper {
    position: absolute;
    animation: x 1s ease-in-out alternate infinite 0s both;
}
.wrapper:nth-of-type(2) {
    animation-delay: 0.1s;
}
.wrapper:nth-of-type(3) {
    animation-delay: 0.2s;
}
.wrapper:nth-of-type(4) {
    animation-delay: 0.3s;
}
.wrapper:nth-of-type(5) {
    animation-delay: 0.4s;
}
.wrapper>div {
    width: 50px;
    height: 50px;
    background-color: #fff;
    border-radius: 100%;
    margin: 40px;
    animation: y 1s linear infinite 0s both;
}
.wrapper:nth-of-type(2)>div {
    animation-delay: 0.1s;
    height: 40px;
    width: 40px;
    opacity: 0.8;
}
.wrapper:nth-of-type(3)>div {
    animation-delay: 0.2s;
    height: 30px;
    width: 30px;
    opacity: 0.6;
}
.wrapper:nth-of-type(4)>div {
    animation-delay: 0.3s;
    height: 20px;
    width: 20px;
    opacity: 0.4;
}
.wrapper:nth-of-type(5)>div {
    animation-delay: 0.4s;
    height: 10px;
    width: 10px;
    opacity: 0.2;
}

@keyframes x {
    0% {
        transform: translateX(-100px)
    }
    100% {
        transform: translateX(100px)
    }
}
@keyframes y {
    25% {
        transform: translateY(-50px)
    }
    0%, 50%, 100% {
        transform: translateY(0)
    }
    75% {
        transform: translateY(50px)
    }
}

body์— ๊ทธ๋ผ๋ฐ์ด์…˜์œผ๋กœ ๋ฐฐ๊ฒฝ์ƒ‰์„ ์ฃผ๊ณ , display: flex๋กœ ๋‹ค์„ฏ ๊ฐœ์˜ ๊ณต์„ ๋ฐฐ์น˜ํ•ด ์ค๋‹ˆ๋‹ค. position: absolute๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํ•œ ๊ณณ์— ๊ณต์„ ํ•ฉ์ณ์ค€ ๋’ค, ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋”œ๋ ˆ์ด ์‹œ๊ฐ„์„ ์ ์ฐจ์ ์œผ๋กœ ๋Š˜๋ ค์ฃผ๊ณ , ํฌ๊ธฐ๋ฅผ ์ ์ฐจ์ ์œผ๋กœ ์ค„์—ฌ์ฃผ๋ฉฐ ์ž”์ƒ์„ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

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

728x90

๋Œ“๊ธ€

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

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